Am try to understand the guts of django, and i cant get any good tutorial on this.
I know django views receive a HttpRequest instance as one of the arguments when they are called, what i would like to know is what function in django internals receive the request from the browser, creates the HttpRequest instance and hands it over to the right view?
Hope am clear!
Gath.
Django uses request and response objects to pass state through the system. When a page is requested, Django creates an HttpRequest object that contains metadata about the request. Then Django loads the appropriate view, passing the HttpRequest as the first argument to the view function.
So, to request a response from the server, there are mainly two methods: GET : to request data from the server. POST : to submit data to be processed to the server.
self. request = request is set in view function that as_view() returns. I looked into the history, but only found setting self. request and then immediately passing request into the view function.
>>> from django.http import HttpRequest
>>> HttpRequest()
<HttpRequest
GET:{},
POST:{},
COOKIES:{},
META:{}>
If you need this for testing and emulating requests, that's fine, but if you try to use this to call views from one another, it's inefficient.
django.core.handlers.base.BaseHandler
is responsible for sending the request through the middleware and then on to the view. The concrete handlers in django.core.handlers
are what actually generate the request object in the first place.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With