In Django, views — these are Python functions that take a URL request as a parameter and return an HTTP response or throw an exception like 404. Each view must be matched against a matching URL pattern. This is done using the Python URLConf (URL setting) module
Let the project name be myProject. The Python module to be used as URLConf is the
ROOT_URLCONF value in
myProject/settings.py . By default this is set to
& # 39; myProject.urls & # 39; . Each URLConf module must contain a
urlpatterns variable that is a set of URL patterns to match against the requested URL. These patterns will be checked sequentially until the first match is found. Then the view corresponding to the first match is called. If the URL pattern does not match, Django invokes the appropriate error handling view.
Including other URLConf modules
It is good practice to have an URLConf module for every application in Django. This module must be included in the root URLConf module as follows:
This tells Django to look for URL patterns in the file
books / urls. py
Here's some sample code for books / urls.py:
views.books_by_genre (request, genre = crime)function.
views.book_detail (request, pk = 25).
str are path converters and captures an integer and a string, respectively.
The following types of path converters are available in Django