I introduced HttpRequest
objects in Chapter 2, Views and URLconfs, when we first covered view functions, but I didn't have much to say about them at the time. Recall that each view function takes an HttpRequest
object as its first parameter, as in our hello()
view:
from django.http import HttpResponse def hello(request): return HttpResponse("Hello world")
HttpRequest
objects, such as the variable request
here, have a number of interesting attributes and methods that you should familiarize yourself with, so that you know what's possible. You can use these attributes to get information about the current request (that is, the user/web browser that's loading the current page on your Django-powered site), at the time the view function is executed.