0PricingLogin
Flask Academy · Lesson

Branch Logic by request.method

Serve a form on GET and process it on POST.

One Route, Two Jobs

A route that accepts both GET and POST often needs to behave differently for each. You handle that by checking which verb arrived.

The request Object

Flask gives you a global request object that describes the incoming call. Import it once and use it inside any view.

from flask import request

All lessons in this course

  1. Declare Allowed Methods on a Route
  2. Branch Logic by request.method
  3. Read POST Data from the Body
  4. 405 Method Not Allowed Explained
← Back to Flask Academy