[英]how to transfer data from one route to another in flask
I'm having some trouble transferring info from a form from one route (main) to another route (score)我在将表单中的信息从一条路线(主要)传输到另一条路线(得分)时遇到了一些麻烦
this is my main route calling the form这是我调用表单的主要途径
@main.route('/', methods=['GET', 'POST'])
def root():
form = form()
if form.validate_on_submit():
form_data = form.score.data
return redirect(url_for('main.score', form_data=form_data))
return render_template('root.html', form=form)
and in the score layout i have this在分数布局中我有这个
{% extends 'layout.html' %}
{% block content %}
<p>{{ form_data.score }}</p>
{% endblock content %}
i want it to display the score that the user inputs into the form我希望它显示用户输入到表单中的分数
and i keep getting this error:我不断收到此错误:
jinja2.exceptions.UndefinedError: 'form_data' is undefined jinja2.exceptions.UndefinedError: 'form_data' 未定义
您应该只呈现分数模板,而不是尝试重定向到它:
return render_template('score.html', form_data=form_data)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.