【发布时间】:2019-11-16 04:32:40
【问题描述】:
让我们有一个带有注册表单的页面。它在#registration 部分。如果用户提交了无效数据,页面应将他返回到#registration 部分并显示向哪些字段提交了无效值。
我尝试渲染模板并做出响应并重定向到它,但我收到了TypeError:
File ".../app/routes.py", line 28, in index
return redirect(url_for('.index', form=form, _anchor='registration'), 302, response)
File ".../python3.7/site-packages/werkzeug/utils.py", line 507, in redirect
mimetype="text/html",
TypeError: __call__() got an unexpected keyword argument 'mimetype'
函数如下所示:
@app.route('/', methods=['GET', 'POST'])
def index():
form = RegisterForm()
if form.validate_on_submit():
# everithing OK
return redirect(url_for('.index', _anchor='registration'))
# If form was submitted but contained invalid information
if form.is_submitted():
response = make_response(render_template('index.html', form=form))
return redirect(url_for('.index', _anchor='registration'), 302, response)
return render_template('index.html', form=form)
【问题讨论】:
标签: python flask redirect single-page-application