Access URL Query Parameters in Flask

Flask – Access URL query parameters

In a flask application, we can access the URL query parameters using request object.

The following is a simple code snippet to access URL query parameter 'name' using request object.


You may replace name with the key for any URL query parameter that you would like to access.

Please note that we need to import request from flask in order to access request object in our Python code.


In this example, we build a flask application where we have following project structure.

Flask project structure

from flask import Flask, render_template, request

app = Flask(__name__)

def home_page():
    name = request.args['name']
    return render_template("index.html", name=name)

if __name__ == "__main__":"", port=8080, debug=True)

We read the value for URL parameter 'name' using the expression request.args['name'].


<!DOCTYPE html>
    <h1>Hello {{name}}!</h1>
    <p>Welcome to sample flask application by <a href=""></a>.</p>

Run Application

Open terminal or command prompt at the root of the application, and run the Python file

Run Flask Application

The flask application is up and running at URL

Now, open a browser of your choice and hit the URL

Python Flask - Access URL query parameters

We have read the URL query parameter in the Python file, and passed it to the HTML template for display.

Project ZIP


In this Python Flask Tutorial, we learned how to access URL query parameter in Python file, with the help of an example flask application.

Related Tutorials

Code copied to clipboard successfully 👍