【发布时间】:2018-10-16 03:25:21
【问题描述】:
我正在开发这个 Flask 应用程序,我按下“登录”按钮并被重定向到“仪表板”。
这是我打开登录页面的默认路由的简化代码:
@app.route('/', methods=['POST', 'GET'])
def home():
if not session.get('logged_in'):
if request.method == 'GET':
return render_template('login.html')
elif request.method == 'POST':
if # Username and Password are correct from the login form
session['logged_in'] = True
return dashboard()
else:
return render_template('login.html', message = "Wrong username or password")
else:
return render_template('dashboard.html')
login.html 有一个带有form action="/" method="POST" 的表单,它在上面的默认路由('/')中触发条件elif request.method == 'POST'
这里是 route('/dashboard') 的简化代码
@app.route('/dashboard', methods=['POST', 'GET'])
def dashboard():
if session.get('logged_in'):
if request.method == 'GET':
return "it was GET"
elif request.method == 'POST':
return "it was POST"
else:
return render_template('login.html')
问题来了。仪表板路由在登录后运行 POST 方法,尽管(根据我的概念)它应该运行 GET 方法(因为 GET 是默认的)。
它给出的输出是“它是 POST”。请帮忙。谢谢:)
【问题讨论】:
标签: python http post flask get