Hackforge Academy

Category: python

routing and url parameters

Published on 30 Sep 2026

Explanation

Flask routes map URLs to Python functions using the @app.route decorator.

Code:

@app.route('/users')
def users():
    return 'Users'

Explanation

A dynamic URL parameter can be defined using angle brackets.

Code:

@app.route('/users/<int:user_id>')
def get_user(user_id):
    return f'User ID: {user_id}'

Explanation

Flask supports converters such as int, float, path, and uuid for URL parameters.

Code:

@app.route('/products/<int:id>')
def product(id):
    return f'Product {id}'

Explanation

Multiple URL parameters can be used in the same route.

Code:

@app.route('/users/<int:user_id>/orders/<int:order_id>')
def order(user_id, order_id):
    return f'User {user_id}, Order {order_id}'

Explanation

A route can restrict which HTTP methods it accepts.

Code:

@app.route('/users', methods=['GET', 'POST'])
def users():
    return 'User API'

πŸš€ Learn Spring Boot with real-world projects

πŸ’‘ Build REST APIs step by step

🧠 Improve backend development skills

🎯 Get career-ready practical training

Join Our Free WhatsApp Community

Direct access to niche-specific mentors and peers on WhatsApp.

🐍

Python Community

Discuss Django, FastAPI, AI integration, and automation scripts with 15k+ developers.

Join Python Community
βš›οΈ

React Community

Master Next.js, Framer Motion, and State Management. Share your latest UI components.

Join React Community
β˜•

Java Community

Deep dives into Spring Boot, Microservices architecture, and high-performance backend ops.

Join Java Community