-
Book Overview & Buying
-
Table Of Contents
Django Project Blueprints
By :
As our aim is to allow users to create dynamic forms based on parameters stored in a database, a good place to start is to look at how a Django form works under the hood and what options we have to customize it. First, let's create a basic form. Create a new main/forms.py file and add the following code to it:
from django import forms
class SampleForm(forms.Form):
name = forms.CharField()
age = forms.IntegerField()
address = forms.CharField(required=False)
gender = forms.ChoiceField(choices=(('M', 'Male'), ('F', 'Female')))This is a pretty basic form. However, it has a variety of form fields that we can look at. Let's play around a bit in the shell, which you can start as follows:
> python manage.py shell
I usually like to install another package called ipython. When you start the Django shell with ipython installed, you get an enhanced version of the basic shell with a lot of cool features such as autocomplete and a much better looking interface...