Loading

Quipoin Menu

Learn • Practice • Grow

flask / Routing Basics
tutorial

Routing Basics

Routing is how you map different URLs to different Python functions. Flask uses decorators to define routes. This allows you to build multi‑page applications.

Simple Routes

@app.route('/')
def home():
return 'Home Page'

@app.route('/about')
def about():
return 'About Page'

Dynamic Routes (Variable Rules)

You can capture parts of the URL as variables.
@app.route('/user/')
def user(name):
return f'Hello, {name}!'

@app.route('/post/')
def show_post(post_id):
return f'Post ID: {post_id}'
Types: `int`, `float`, `path` (accepts slashes).

URL Building with `url_for`

Instead of hard‑coding URLs, use `url_for()` to generate them dynamically.
from flask import url_for

with app.test_request_context():
print(url_for('user', name='alice')) # /user/alice

Multiple Routes for One Function

You can add multiple decorators to the same function.
@app.route('/')
@app.route('/index')
def index():
return 'Welcome!'


Two Minute Drill
  • Use `@app.route('/path')` to map URLs to functions.
  • Dynamic routes: `` or ``.
  • `url_for()` generates URLs by function name.
  • One function can have multiple routes.

Need more clarification?

Drop us an email at career@quipoinfotech.com