Multiple Routes in One App
Add several pages and avoid route collisions.
Multiple Routes in One App is a free Flask Academy lesson on CoddyKit — lesson 4 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the Flask Academy learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.
Many Pages, One App
A real site has many pages. You add each one with its own route and view function, all living inside the same app file.
Stack the Decorators
Just write more @app.route blocks. Each pairs a unique path with its own function, and Flask keeps track of every one.
@app.route("/home")
def home():
return "Home"Add Another Page
Below the first route, add a second for a new path like /about. Two routes, two functions, two pages your users can visit.
@app.route("/about")
def about():
return "About"Each Path Is Unique
Two routes must not share the same path. If they do, Flask cannot tell which view to call and raises an error at startup.
The Collision Error
Reusing a path triggers a collision. Flask warns that the endpoint is already registered, so give every route a distinct URL.
Function Names Must Differ
Each view also needs a unique function name. Two functions named home overwrite each other, and only the last one survives.
Endpoints Behind the Scenes
Flask stores each route under an endpoint name, which defaults to the function name. That name is how Flask refers to the route internally.
Group Related Routes
Keep related pages near each other in the file. Good grouping makes a growing app easier to read and to maintain over time.
Order Does Not Decide Matching
Flask picks a route by the requested path, not by source order. So the position of a route in the file does not change which page loads.
One File Has Limits
Dozens of routes in one file get unwieldy. Later you will split them into blueprints, but for now a single file is perfectly fine.
A Small Multi-Page App
Here is the shape: distinct paths, distinct names, one app. Add a contact route the same way and your site keeps growing.
@app.route("/contact")
def contact():
return "Contact"Quick Check
Spot what causes a route collision.
Recap
You build many pages by stacking routes, each with a unique path and name. Keep them tidy now, and blueprints will scale you later. 🧭
Frequently asked questions
Is the “Multiple Routes in One App” lesson free?
Yes — the full text of “Multiple Routes in One App” is free to read here on the web, and the Flask Academy course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the Flask Academy course, upgrade to CoddyKit PRO.
What will I learn in “Multiple Routes in One App”?
Add several pages and avoid route collisions. You practise Flask Academy with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.
Do I need any experience to start Flask Academy?
No prior experience is required. Flask Academy on CoddyKit is structured for beginners through advanced learners; this is — lesson 4 of 4, so you can start here or from the beginning and move at your own pace.
How long does the “Multiple Routes in One App” lesson take?
Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.
Can I write and run code in this Flask Academy lesson?
Yes. Every Flask Academy lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.
All lessons in this course
- The @app.route Decorator
- How a Request Becomes a Response
- Return Strings, HTML, and Status Codes
- Multiple Routes in One App