Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Which function in django creates a HttpRequest instance and hands to a view?

Tags:

django

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.

like image 596
gath Avatar asked Nov 12 '10 07:11

gath


People also ask

What is HttpRequest in Django?

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.

What are request get and request post objects?

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.

What is self request in Django?

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.


2 Answers

>>> 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.

like image 173
culebrón Avatar answered Sep 21 '22 09:09

culebrón


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.

like image 39
Ignacio Vazquez-Abrams Avatar answered Sep 17 '22 09:09

Ignacio Vazquez-Abrams