View method requests

So far you've worked with Django view methods and their input -- a request object and parameters -- as well as their output, consisting of generating a direct response or relying on a template to generate a response. However, now it's time to take a deeper look at what's available in view method requests and the various alternatives to generate view method responses.

The request reference you've placed unquestionably in view methods up to this point, is an instance of the django.http.request.HttpRequest class[3]. This request object contains information set by entities present before a view method: a user's web browser, the web server that runs the application or a Django middleware class configured on the application.

The following list shows some of the most common attributes and methods available in a request reference:

As you can attest from this brief list, the request reference contains a lot of actionable information to fulfill business logic (e.g. you can respond with certain content based on geolocation information from a user's IP address). There are well over fifty request options available between django.http.request.HttpRequest & django.http.request.QueryDict attributes and methods, all of which are explained in parts of the book where they're pertinent -- however you can review the full extent of request options in the footnote link of the django.http.request.HttpRequest class.

Once you're done extracting information from a request reference and doing related business logic with it (e.g. querying a database, fetching data from a third party REST service) you then need to set up data in a view method to send it out as part of a response.


  1. https://docs.djangoproject.com/en/4.0/ref/request-response/#django.http.HttpRequest    

  2. https://docs.djangoproject.com/en/4.0/ref/request-response/#django.http.QueryDict