我正在用 Flask 构建一个小型网络应用程序,代码摘录如下。基本上,我试图将一些数据存储在 startsession
中,然后在完成后转到 tagpage
。但是 redirect
不起作用。
当我运行 TEST 1
时,它在控制台中显示 hello, world
但主页面看起来一样。
当我运行 TEST 2
时,它会在控制台中显示 html,但主页看起来是一样的。
这是我的:
@app.route('/startsession', methods=['POST'])
def startsession():
_username = request.form['inputName']
session['user_name'] = _username
...
return redirect(url_for('tagpage'))
然后,要么:
### TEST 1
@app.route("/tagpage")
def tagpage():
return "hello, world"
或者:
### TEST 2
@app.route("/tagpage")
def tagpage():
return render_template('tagpage.html', filename=filename)
单击触发 startsession
的按钮后我看到的示例:
如何让浏览器真正转到 http://localhost:5000/tagpage
?
更新: 这是我的 JQuery 脚本:
$(function(){
$("#btnStartSession").click(function(){
$.ajax({
url: '/startsession',
type: 'POST',
data: $('form').serialize(),
success: function(response){
console.log(response);
},
error: function(error){
console.log(error);
}
});
});
});