Chapter 7. Forms

HTML forms are the backbone of interactive Web sites, 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

We introduced HttpRequest objects in Chapter 3 when we first covered view functions, but we 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") ...

Get The Definitive Guide to Django: Web Development Done Right, Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.