HTTP Methods (GET & POST)
An HTTP method is the type of action a request performs: GET asks the server for something (a page or data), while POST sends data to the server, such as a submitted form.
Learn HTTP Methods (GET & POST) in our free Flask course — a beginner-friendly interactive lesson with worked examples, a practice exercise and a quick…
Part of the free Flask course at LearnCodingFast — hands-on lessons with examples you run in your browser, plus practice exercises and a quick quiz.
In this lesson you'll let routes accept POST, read submitted form data with request.form , and handle GET and POST in one view function. Try each app locally with flask run .
Every request a browser makes has an HTTP method . The two you'll use most are:
By default, a Flask route only answers GET . To accept POST you list it in the decorator with methods=["GET", "POST"] . The app below allows both and reports which method was used by reading request.method .
When a form is submitted with POST, the values land in request.form , which works like a dictionary keyed by each input's name . Use request.form.get("field") to read a value safely — it returns None instead of crashing if the field is missing.
The app below shows a login-style form on GET and greets the user on POST after reading the username field they typed.
The form's method="POST" attribute is what sends the data in the body. Each input's name becomes the key you read from request.form .
GET requests can still carry data — in the query string , the part of a URL after the ? . Flask exposes those values in request.args . For example, a search box might link to /search?q=flask .
Finish a route that accepts a POST and reads an email field. Replace each ___ .
You submitted a POST to a route that only allows GET. Add methods=["GET", "POST"] to the @app.route decorator.
The field wasn't in the submission, so the dictionary lookup failed. Use request.form.get("x") instead, which returns None rather than raising.
Build a single route that shows a feedback form and processes it.
Lesson 4 complete — your app can receive data!
You now know the difference between GET and POST, how to allow methods on a route, and how to read user input from request.form and request.args . That's the foundation of every interactive web app.
🚀 Up next: Templates with Jinja2 — stop returning inline HTML and render real template files instead.
Practice quiz
What is the GET method used for?
- Deleting a resource
- Asking the server for a resource
- Encrypting data
- Restarting the server
Answer: Asking the server for a resource. GET asks the server for something, like a page or data.
Where does data travel in a POST request?
- In the URL path
- In the response
- In the request body
- In a cookie
Answer: In the request body. POST sends data in the request body, not the URL.
By default, which method does a Flask route accept?
- POST only
- Both GET and POST
- PUT only
- GET only
Answer: GET only. A route answers only GET unless you list other methods.
How do you allow POST on a route?
Add methods=["GET", "POST"] to the @app.route decorator.
Where do submitted POST form values appear?
- request.args
- request.form
- request.cookies
- request.path
Answer: request.form. Posted form fields are read from request.form.
How do you check which method a request used?
- request.verb
- request.type
- request.method
- request.kind
Answer: request.method. request.method holds the HTTP method string, e.g. "POST".
Where do query-string values (after ?) appear?
- request.form
- request.body
- request.cookies
- request.args
Answer: request.args. Query string values are exposed in request.args.
Why prefer request.form.get("x") over request.form["x"]?
- It returns None instead of raising when the field is missing
- It is faster
- It validates the value
- It logs the request
Answer: It returns None instead of raising when the field is missing. .get() avoids a 400/KeyError when a field wasn't submitted.
What HTTP error means you POSTed to a GET-only route?
- 404 Not Found
- 405 Method Not Allowed
- 500 Internal Error
- 302 Found
Answer: 405 Method Not Allowed. 405 Method Not Allowed means the verb isn't permitted on that route.
For a search box linking to /search?q=flask, how do you read q?
- request.form.get("q")
- request.path
Query parameters are read from request.args.