-
Book Overview & Buying
-
Table Of Contents
Mastering Django: Core
By :
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.
HttpRequest objects contain several pieces of information about the currently requested URL (Table 6.1).
|
Attribute/method |
Description |
Example |
|
|
Change the font size
Change margin width
Change background colour