How Django processes a request?

Submitted 3 years, 5 months ago
Ticket #274
Views 240
Language/Framework Django
Priority Low
Status Closed

How Django processes a request?

Submitted on Nov 02, 20
add a comment

1 Answer

Verified

When a user requests a page from your Django-powered site, this is the algorithm the system follows to determine which Python code to execute:


Django determines the root URLconf module to use. Ordinarily, this is the value of the ROOT_URLCONF setting, but if the incoming HttpRequest object has an attribute called urlconf (set by middleware request processing), its value will be used in place of the ROOT_URLCONF setting.
Django loads that Python module and looks for the variable urlpatterns. This should be a Python list, in the format returned by the function django.conf.urls.patterns()
Django runs through each URL pattern, in order, and stops at the first one that matches the requested URL.

Once one of the regexes matches, Django imports and calls the given view, which is a simple Python function (or a class based view). The view gets passed an HttpRequest as its first argument and any values captured in the regex as remaining arguments.

If no regex matches, or if an exception is raised during any point in this process, Django invokes an appropriate error-handling view.

Submitted 3 years, 5 months ago


Latest Blogs