Appendix H. Request and Response 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.

We've used these objects often throughout the book; this appendix explains the complete APIs for HttpRequest and HttpResponse objects.


HttpRequest represents a single HTTP request from some user-agent.

Much of the important information about the request is available as attributes on the HttpRequest instance (see Table H-1). All attributes except session ...

Get The Definitive Guide to Django: Web Development Done Right now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.