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