python - 烧瓶 - 如何发送数据并将其取回
问题描述
我正在烧瓶中开发一个小应用程序,我需要让用户一一回答 20 个随机问题。我有一个问题列表,我想在每次用户按下“下一步”按钮时向 html 发送一个问题。
@app.route('/handleQuestions', methods=['GET', 'POST'])
def handleQuestions():
#first time - first question
if not request.method == 'POST':
try:
pdQuestions = GetShuffeledQuestions()
session['pdQuestions'] = pdQuestions
i=0
session['qindex']=i
questionTosend = session.get('pdQuestions').iloc[[i]]['question'].item()
print(questionTosend)
return render_template('questionsTemplate.html',progress=round((i/24)*100), sent=questionTosend)
except Exception as ex:
print(ex)
else:
answer = request.form.to_dict(flat=False)
print(answer)
#next question
i=session['qindex']+1
session['qindex']=i
questionTosend = session.get('pdQuestions').iloc[[i]]['question'].item()
print(questionTosend)
return render_template('questionsTemplate.html',progress=round((i/24)*100), sent=questionTosend)
print('done')
我在哪里可以保存清单?以及如何将其迭代到页面?我希望用户每次得到 1 个问题,我会保存答案并给他下一个问题。
我试图将其保存在会话中,但列表太大,当我将其保存到会话时它会崩溃。
解决方案
推荐阅读
- kerberos - 为什么 kerberos 集合没有列出有效的主体?
- python - 将 postgres 表导出到 yaml 文件
- python - SQLite 和 Python 的问题
- c# - C# 调用字典
基于从另一个字典返回的值 - python - Instabot 信号仅在主线程中有效
- json - 如何使用 JMeter 中的 JSON 提取器提取 JSON 响应中的嵌套元素
- python - python请求的HTTPS连接错误
- python - 模型返回错误 - ValueError:logits 和标签必须具有相同的形状 ((None, 18) vs (None, 1))
- javascript - 如何使用 jQuery 设置 php 值的颜色?
- c# - 使 REST API 仅响应已知客户端