I am trying to learn more about Flask for a project, and I wonder if someone can explain to me why the "GET" and "POST" methods are listed in the sample code when it only ever tries to process login if the request was "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'))
source share