Starting with urls.py
Even if you have access to the entire source code of a Django site, figuring out how it works across various apps can be daunting. Often, it is best to start from the root URLconf
located in the urls.py
, file since it is literally a map that ties every request to the respective views.
With normal Python programs, I often start reading from the start of its execution–say, from the top-level main module or wherever the __main__
check idiom starts. In the case of Django applications, I usually start with urls.py
since it is easier to follow the flow of execution based on the various URL patterns a site has.
In Linux, you can use the following find
command to locate the settings.py
file and the corresponding line specifying the urls.py
root:
$ find . -iname settings.py -exec grep -H 'ROOT_URLCONF' {} \;./projectname/settings.py:ROOT_URLCONF = 'projectname.urls'$ ls projectname/urls.pyprojectname/urls.py