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