我收到以下错误:
" werkzeug.routing.BuildError:无法为端点构建网址 ' setpassword&#39 ;.您是否忘记指定值['令牌']?"
main.py:
@app.route('/setpassword/<token>',methods=['GET','POST'])
def setpassword(token):
form = PasswordForm()
return render_template('setpassword.html',form=form, token=token)
setpassword.html:
{% extends "base.html" %}
{% import "bootstrap/wtf.html" as wtf %}
{% from '_macros.html' import hello %}
{% block title %}SetPassword{% endblock %}
{% block content %}
{% for i in form.password.validators %}
{{ i.message }}
{% endfor %}
<form class="form form-horizontal " action="{{ url_for('setpassword') }}" method=post role="form">
{{ form.hidden_tag() }}
{{ wtf.form_field(form.password, hiddens='True',placeholder='Enter Password') }}
{% for e in form.password.errors %}
<span class="label label-danger" id="labelerror">{{ e }}</span>
{% endfor %}
{{ wtf.form_field(form.confirm, class='form-control' , placeholder='Confirm Password') }}
{{ wtf.form_field(form.submit , class='btn btn-primary btn-block' ) }}
</form>
{% endblock %}
为什么会出现此错误,如何阻止错误发生?
答案 0 :(得分:0)
url_for
获取变量的关键字参数。所以你可以像这样编写动作网址
<form action="{{ url_for('setpassword', token=token) }}">