What if you could write one route that magically handles thousands of different pages?
Why Route with dynamic parameters in Flask? - Purpose & Use Cases
Imagine building a website where you want to show user profiles by typing URLs like /user/123 or /user/456. Without dynamic routes, you'd have to create a separate page for each user manually.
Manually creating a route for every user is impossible to maintain and very slow. Every time a new user joins, you'd need to add new code. This quickly becomes a huge mess and wastes time.
Using routes with dynamic parameters, Flask lets you write one route that automatically handles many URLs by capturing parts of the URL as variables. This means one route can serve all user profiles dynamically.
@app.route('/user/123') def user_123(): return 'User 123 profile'
@app.route('/user/<int:user_id>') def user_profile(user_id): return f'User {user_id} profile'
This lets your web app respond to many different URLs with just one route, making your code cleaner and your app scalable.
Think of an online store where each product has its own page. Instead of coding each product page separately, dynamic routes let you show any product by its ID in the URL like /product/789.
Manual routes for each URL are hard to maintain.
Dynamic parameters let one route handle many URLs.
This makes your app flexible and easier to build.