Static and Dynamic Routing
Let's learn how to create static and dynamic URL routes in our application.
What is static and dynamic routing?
Routing can be of two types, static or dynamic. To understand static routing, we can consider a specific URL that leads to a specific page. For example, /home
take us to the home page of a website and /about
takes us to the about page. However, these are not the only kinds of URLs. In social media sites, we can have URLs such as /profile/101011
and /profile/102045
. These URLs lead us to the same page, but depending on the variable part of the URL, the content shown can be different. This is called dynamic routing.
Now, let’s learn how to implement these routing options in Django.
Static routing
In static routing, we specify a constant URL string as a path in the urls.py
file.
For example, in the mini-application given below, we have specified two static routes with the URLs home/
and educative/
respectively.
📌 NOTE: The path is a case-sensitive string. Therefore,
/educative
and/Educative
are two different URLs.
Get hands-on with 1400+ tech skills courses.