Chapter 6. Forms

HTML forms are the backbone of interactive websites, from the simplicity of Google's single search box to ubiquitous blog comment submission forms to complex custom data-entry interfaces.

This chapter covers how you can use Django to access user-submitted form data, validate it and do something with it. Along the way, we'll cover HttpRequest and Form objects.

Getting data from the Request Object

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 ...

Get Mastering Django: Core now with O’Reilly online learning.

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