GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Python Tutorial
  • Data Types
  • Interview Questions
  • Examples
  • Quizzes
  • DSA Python
  • Data Science
  • NumPy
  • Pandas
  • Practice
  • Django
  • Flask
  • Introduction1 min read
  • Input & Output2 min read

This view

  • Original page
  • New address

GeezerVison is showing www.geeksforgeeks.org — Python Flask - Request Object - GeeksforGeeks

geeksforgeeks
search icon
  • Courses
  • Tutorials
  • Interview Prep
  • Python Tutorial
  • Data Types
  • Interview Questions
  • Examples
  • Quizzes
  • DSA Python
  • Data Science
  • NumPy
  • Pandas
  • Practice
  • Django
  • Flask

Python Flask - Request Object

Last Updated : 26 Jun, 2026

The request object in Flask contains all the data associated with an incoming HTTP request. It allows applications to access information sent by the client, such as form data, query parameters, uploaded files, cookies, headers and the HTTP request method. It's provided by Flask and represents the current HTTP request sent by the client to the server. It's used for:

  • Retrieve form data submitted by users.
  • Access URL query parameters.
  • Read uploaded files.
  • Access cookies and request headers.
  • Determine the HTTP request method (GET, POST, etc.).

Request Object Attributes

AttributeDescription
request.formRetrieves data submitted through HTML forms using the POST method.
request.argsRetrieves query parameters from the URL.
request.filesAccesses uploaded files.
request.cookiesRetrieves cookies sent by the browser.
request.methodReturns the HTTP request method (GET, POST, etc.).
request.headersRetrieves HTTP headers sent by the client.

Example: Process and Display User Form Data

The following example demonstrates how to use Flask's request object to retrieve user-entered data from an HTML form and display it on another webpage. The application works as follows:

  • The user opens a webpage containing a registration form.
  • The user enters their details and clicks Submit.
  • The form sends a POST request to the Flask server.
  • The server retrieves the submitted data using request.form.
  • The data is passed to another HTML page and displayed in a table.

Create a Flask Application and an app.py file.

Python
from flask import Flask, render_template, request
app = Flask(__name__)
@app.route('/')
def input():
    return render_template('Temp.html')
@app.route('/passing', methods=['GET', 'POST'])
def display():

    if request.method == 'POST':
        result = request.form
        return render_template(
            'result_data.html',
            result=result
        )

if __name__ == '__main__':

    app.run(debug=True)

Explanation:

  • Flask(__name__) creates a Flask application instance.
  • / renders the HTML form page.
  • /passing handles the submitted form data.
  • methods=['GET', 'POST'] allows both request methods.
  • request.method checks whether the request is a POST request.
  • request.form retrieves all submitted form data.
  • render_template() passes the data to result_data.html.

Inside the templates folder, create Temp.html.

HTML
<html>
<style>
body {
    text-align: center;
    background-color: green;
}
form {
    display: inline-block;
}
</style>
<body>
    <h3>Please Fill Out This Form</h3>
    <form action="/passing" method="POST">
        <p>Name <input type="text" name="name" /></p>
        <p>Email <input type="email" name="email" /></p>
        <p>Phone Number <input type="text" name="phone" /></p>
        <p><input type="submit" value="Submit" /></p>
    </form>
</body>
</html>

Explanation:

  • action="/passing" sends the form data to the /passing route.
  • method="POST" sends the data as a POST request.
  • Each input field has a name attribute that Flask uses to identify the data.
  • Clicking Submit sends the data to the server.

Inside the templates folder, create result_data.html.

HTML
<!doctype html>
<html>
<style>
body {
    text-align: center;
    background-color: orange;
}
table {
    display: inline-block;
    border-collapse: collapse;
}
</style>
<body>
    <p><strong>Registration Successful</strong></p>
    <table border="1">
        {% for key, value in result.items() %}
        <tr>
            <th>{{ key }}</th>
            <td>{{ value }}</td>
        </tr>
        {% endfor %}
    </table>
</body>
</html>

Explanation:

  • result.items() retrieves all submitted form fields.
  • The {% for %} loop iterates through each key-value pair.
  • <th> displays the field name.
  • <td> displays the corresponding value.
  • The submitted data is displayed in a table format.

Run the Application

Open a terminal and run:

python app.py

Open the following URL in your browser:

http://127.0.0.1:5000/

Output

Screenshot-2026-06-23-144830
Screenshot-2026-06-23-144807
Screenshot-2026-06-23-144813
Comment

Explore

    Python Fundamentals
    • Introduction1 min read
    • Input & Output2 min read
    • Variables4 min read
    • Operators4 min read
    • Keywords2 min read
    • Data Types4 min read
    • Conditional Statements3 min read
    • Loops3 min read
    • Functions4 min read
    Python Data Structures
    • String4 min read
    • List3 min read
    • Tuples3 min read
    • Dictionary3 min read
    • Set2 min read
    • Arrays5 min read
    Advanced Python
    • OOP Concepts3 min read
    • Exception Handling5 min read
    • File Handling4 min read
    • Python Database2 min read
    • MongoDB3 min read
    • MySQL7 min read
    • Packages4 min read
    • Modules3 min read
    • DSA Libraries5 min read
    • Python GUI2 min read
    Data Science with Python
    • Numpy3 min read
    • Pandas4 min read
    • Matplotlib3 min read
    • Seaborn3 min read
    • StatsModel2 min read
    • Model Building6 min read
    • TensorFlow2 min read
    • PyTorch5 min read
    Web Development with Python
    • Flask3 min read
    • Django5 min read
    • Django ORM4 min read
    • Jinja2 Templating5 min read
    • Django Templates5 min read
    • REST API3 min read
    • Build API with DRF4 min read
    Python Practice
    • Quiz1 min read
    • Practice Problems2 min read
    • Interview Q & A15+ min read
    Courses
    • Placement 360 Course2 min read
    • Data Science 360 Course2 min read
    • AI Engg Course2 min read
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.