How Django Processes a Request
When a request comes in for a particular URL – say, a request for /hello/ – Django loads the URLconf pointed to by the ROOT_URLCONF setting. Then it checks each of the URLpatterns in that URLconf, in order, comparing the requested URL with the patterns one at a time, until it finds one that matches. When it finds one that matches, it calls the view function associated with that pattern, passing it an HttpRequest object as the first parameter. (We’ll cover the specifics of HttpRequest later.)
In summary:
- A request comes in to /hello/.
- Django determines the root URLconf by looking at the ROOT_URLCONF setting.
- Django looks at all of the URLpatterns in the URLconf for the first one that matches /hello/.
- If it finds a match, it calls the associated view function.
- The view function returns an HttpResponse.
- Django converts the HttpResponse to the proper HTTP response, which results in a Web page.
No comments:
Post a Comment