Learning Flask: Part 2: Routes

Learning Flask

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


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!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.