Google News
logo
Django - Interview Questions
What is Django HttpRequest and HttpResponse Objects?
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. Each view is responsible for returning an HttpResponse object.
# importing HttResponse from library
from django.http import HttpResponse
 
def home(request):
    # request is handled using HttpResponse object
    return HttpResponse("Any kind of HTML Here")

 

Advertisement