Book Image

Mastering Django: Core

By : Nigel George
Book Image

Mastering Django: Core

By: Nigel George

Overview of this book

Mastering Django: Core is a completely revised and updated version of the original Django Book, written by Adrian Holovaty and Jacob Kaplan-Moss - the creators of Django. The main goal of this book is to make you a Django expert. By reading this book, you’ll learn the skills needed to develop powerful websites quickly, with code that is clean and easy to maintain. This book is also a programmer’s manual that provides complete coverage of the current Long Term Support (LTS) version of Django. For developers creating applications for commercial and business critical deployments, Mastering Django: Core provides a complete, up-to-date resource for Django 1.8LTS with a stable code-base, security fixes and support out to 2018.
Table of Contents (33 chapters)
Mastering Django: Core
Credits
About the Author
www.PacktPub.com
Preface
Free Chapter
1
Introduction to Django and Getting Started

Making a contact form


Although we iterated over the book search form example several times and improved it nicely, it's still fundamentally simple: just a single field, 'q'. As forms get more complex, we have to repeat the preceding steps over and over again for each form field we use. This introduces a lot of cruft and a lot of opportunities for human error. Lucky for us, the Django developers thought of this and built into Django a higher-level library that handles form-and validation-related tasks.

Your first form class

Django comes with a form library, called django.forms, that handles many of the issues we've been exploring this chapter-from HTML form display to validation. Let's dive in and rework our contact form application using the Django forms framework.

The primary way to use the forms framework is to define a Form class for each HTML <form> you're dealing with. In our case, we only have one <form>, so we'll have one Form class. This class can live anywhere you want...