我正在尝试为一个项目了解有关 Flask 的更多信息,我想知道是否有人可以向我解释为什么示例代码列出了方法 'GET' 和 'POST',当它只尝试处理登录时,如果请求是“POST”?
@app.route('/login', methods=['GET', 'POST'])
def login():
error = None
if request.method == 'POST':
if request.form['username'] != app.config['USERNAME']:
error = 'Invalid username'
elif request.form['password'] != app.config['PASSWORD']:
error = 'Invalid password'
else:
session['logged_in'] = True
flash('You were logged in')
return redirect(url_for('show_entries'))
# Note that nowhere do we seem to care about 'GET'...
return render_template('login.html', error=error)