URL Mappings
Let's cover the URL mappings using the "include()" function.
We previously showed a direct mapping that imported the views.py
file into the urls.py
file of our projects. So, we were connecting views of our application to the urls.py
file of the project itself. However, this solution is not modular. Let’s examine why.
Consider that we have a large scale project that might include various applications. Moreover, the project will also likely have several URL paths, where most paths will be application-specific. So, for a modular solution, we would prefer that the paths specific to an application be declared inside the application folder. This is where the include
function will come in and help us out.
The include()
function
The include()
function allows us to look for a match with the path defined in the urls.py
file of our project, and ...