Learning Flask: Part 2: Routes

Learning Flask

Flask is a microframework for server-side web development in Python.


Routes

Flask works through reacting to routes. In the terminology of Flask, a route is a URL path defined from the root directory outwards.

A route is defined through the route() function and a parameter describing the path.

Routes are decorators in Flask. They are associated with other functions that run when the route is detected on the server.

Variable Routes

While absolute URL paths can be defined, variable routes also exist.

When part of a path is enclosed in less-than and greater-than signs, it becomes a variable for the route. This becomes the name of the parameter passed to the function and thus available within it.

Variable routes can thus be used to handle unexpected and routes that exist to react to internal data or as part of retrieving information from a database.

Play with the example on Repl.it!