javascript - 页面加载错误上的 Flask 发布请求
问题描述
每当我刷新我的页面时,都会在我的控制台中看到一个发布请求。这意味着它会在我输入任何内容或单击任何按钮之前请求我的表单。我需要将它传递给 Jinja 并通过 js,但是,它总是返回 0,因为变量用户名或密码中没有数据。
@app.route('/dosomething', methods = ['POST', 'GET'])
def dosomething():
if request.method == 'POST':
username = request.form['username']
password = request.form['password']
check = system.add_user(username,password)
if check == 1:
return redirect(url_for("login"))
return render_template('dosomething.html', check = check)
return render_template('dosomething.html')
解决方案
您必须使用 307 http 代码重定向。
if check == 1:
return redirect(url_for('login'), code=307)
推荐阅读
- coffeescript - 使用 pm2 运行咖啡代码时出错:错误:spawn /usr/local/lib/node_modules/pm2/node_modules/.bin/coffee ENOENT
- ios - Unable to use po command in console (debug area)
- mdx - 问题出在哪里:函数需要 2 参数的元组表达式。使用了元组集表达式。错误
- python - Maya – 通过 Python 在视口中选择对象
- cakephp - CSRF 中间件没有被激活
- bbedit - 更改搜索窗口中换行符的默认显示?
- list - 数组颤动中的颜色容器
- sql - 自动增量无
- c# - 如何为具有 console.writeline 的代码编写 MS 单元测试
- php - PHP - 根据 axios 请求调用 setcookie() 时不起作用