May 2018
Beginner to intermediate
282 pages
7h 58m
English
In many ways, urls.py is the entry point for your project. It is usually the first file I open when I study a Django project. It is like reading a map before exploring a terrain. Essentially, urls.py contains the root URL configuration or URLConf of the entire project.
It is a Python list of patterns assigned to a global variable called urlpatterns. Each incoming URL is matched with each pattern from top to bottom in a sequence. In the first match, the search stops, and the request is sent to the corresponding view.
Here is an excerpt of urls.py from python.org, which is built in Django:
urlpatterns = [
# Homepage
url(r'^$', views.IndexView.as_view(), name='home'),
# About url(r'^about/$', TemplateView.as_view(template_name="python/about.html"), ...Read now
Unlock full access