Dynamic Routing
In this lesson, we will learn how to create dynamic URL routes in our application.
Introduction
There are different parameters that can be passed to the route
decorator. In static routing, the rule
parameter of the route
decorator is a simple string. However, in dynamic routing, the rule
parameter is not a constant string. Instead, a variable rule is passed to the route()
. Let’s figure out how this is done!
Variable rules
In Flask
we can add variable rules inside the URL route by using the following syntax: <variable_name>
. The variable called variable_name
will then be passed to the view function to be used.
An example using variable rules
Get hands-on with 1400+ tech skills courses.