6
我有一個調查表。提交表單後,我想處理保存數據,然後重定向到「成功」視圖。我現在正在使用下面的代碼,但它只停留在當前的URL上,而我想去/success
。我怎樣才能做到這一點?提交表單後重定向到其他視圖
@app.route('/surveytest', methods=['GET', 'POST'])
def surveytest():
if request.method == 'GET':
return render_template('test.html', title='Survey Test', year=datetime.now().year, message='This is the survey page.')
elif request.method == 'POST':
name = request.form['name']
address = request.form['address']
phone = request.form['phone']
email = request.form['email']
company = request.form['company']
return render_template('success.html', name=name, address=address, phone = phone, email = email, company = company)
你也可以使用[flash messages](http://flask.pocoo.org/docs/0.10/patterns/flashing/)。 – dirn