【发布时间】:2017-05-05 23:24:28
【问题描述】:
我正在学习 Flask,但在将参数传递给 URL 以在另一个页面上使用时遇到了一些问题。例如,我在/index 上有一个表单,我希望它重定向到可以打印表单数据的/results 页面。我的尝试是这样的:
from flask import render_template
from flask import redirect
from flask import url_for
from app import app
from .forms import LoginForm
@app.route('/')
@app.route('/index', methods=['GET', 'POST'])
def login():
form = LoginForm()
if form.validate_on_submit():
name = form.artistName.data
return redirect(url_for('result', name=name))
else:
return redirect('/index')
return render_template('index.html',
title='Sign In',
form=form)
@app.route('/result/<name>')
def result(name):
return render_template('results.html')
重定向到 /results 页面时,我收到 405 错误 Method not allowed for the requested URL。我想使用表单的结果作为参数在/results 上构造一个 URL。
我该怎么做?非常感谢
【问题讨论】:
-
你能添加你所面临的错误的堆栈跟踪吗?
-
请发布错误回溯消息。
-
我在重定向到
/results页面时收到 405 错误Method not allowed for the requested URL。
标签: python redirect flask http-status-code-405