Data Handling Using the Request Object
In this lesson, we will handle the POST request received by the login template and retrieve the data from it.
We'll cover the following...
We'll cover the following...
📌 How can we know if a particular request is
GETorPOST?
This is where therequestobject comes in handy. Let’s find out more about therequestobject.
Accessing form data
To access the data sent by a user, we use the global request object. Before we start using it, let’s import it from the flask module.
from flask import request
Getting the Method type from request
We can use the method member variable of the request object to determine the method of an incoming request.
Consider the snippet given below.
@app.route("/login", methods=["GET", "POST"])def login():if request.method == "POST":...else...return render_template("login.html")