0% developed

Making Websites with Flask/Routing

From Wikibooks, open books for an open world
Jump to navigation Jump to search

What is Routing?[edit | edit source]

Routing basically means returning something to the user when they visit a specific URL on the site, which is called a route. In the Getting Started tutorial, we had two routes: the root route, /, and /hello.

URL Building with Route Variables[edit | edit source]

URL building is the practice of having dynamically served URLs, that are not built in. An example of this would be if you had a /user route, but the URL was formatted like /user/randomUser. In a Flask app without route variables, you would manually need to add each user with @app.route many times, but with Route Variables you can just say @app.route('/user/<name>'), and you can show the account page.