From 8b837ba33dcaa6497ed9a7ffe7466dddb3af0e73 Mon Sep 17 00:00:00 2001
From: Adrian Holovaty
Date: Sun, 28 Jan 2007 22:26:25 +0000
Subject: [PATCH] newforms-admin: Merged to [4440]
git-svn-id: http://code.djangoproject.com/svn/django/branches/newforms-admin@4441 bcc190cf-cafb-0310-a4f2-bffc1f526a37
---
django/newforms/fields.py | 62 +++++++-------
django/newforms/forms.py | 27 +++++--
django/newforms/models.py | 19 +++--
django/newforms/widgets.py | 15 +++-
docs/newforms.txt | 32 ++++++++
tests/modeltests/model_forms/models.py | 41 ++++++++++
tests/regressiontests/forms/tests.py | 107 +++++++++++++++++++++++++
7 files changed, 253 insertions(+), 50 deletions(-)
diff --git a/django/newforms/fields.py b/django/newforms/fields.py
index bcd30dbc92..e9e1fb7746 100644
--- a/django/newforms/fields.py
+++ b/django/newforms/fields.py
@@ -35,7 +35,7 @@ class Field(object):
# Tracks each time a Field instance is created. Used to retain order.
creation_counter = 0
- def __init__(self, required=True, widget=None, label=None, initial=None):
+ def __init__(self, required=True, widget=None, label=None, initial=None, help_text=None):
# required -- Boolean that specifies whether the field is required.
# True by default.
# widget -- A Widget class, or instance of a Widget class, that should be
@@ -47,9 +47,11 @@ class Field(object):
# field name, if the Field is part of a Form.
# initial -- A value to use in this Field's initial display. This value is
# *not* used as a fallback if data isn't given.
+ # help_text -- An optional string to use as "help text" for this Field.
if label is not None:
label = smart_unicode(label)
self.required, self.label, self.initial = required, label, initial
+ self.help_text = help_text
widget = widget or self.widget
if isinstance(widget, type):
widget = widget()
@@ -85,9 +87,9 @@ class Field(object):
return {}
class CharField(Field):
- def __init__(self, max_length=None, min_length=None, required=True, widget=None, label=None, initial=None):
+ def __init__(self, max_length=None, min_length=None, *args, **kwargs):
self.max_length, self.min_length = max_length, min_length
- super(CharField, self).__init__(required, widget, label, initial)
+ super(CharField, self).__init__(*args, **kwargs)
def clean(self, value):
"Validates max_length and min_length. Returns a Unicode object."
@@ -106,9 +108,9 @@ class CharField(Field):
return {'maxlength': str(self.max_length)}
class IntegerField(Field):
- def __init__(self, max_value=None, min_value=None, required=True, widget=None, label=None, initial=None):
+ def __init__(self, max_value=None, min_value=None, *args, **kwargs):
self.max_value, self.min_value = max_value, min_value
- super(IntegerField, self).__init__(required, widget, label, initial)
+ super(IntegerField, self).__init__(*args, **kwargs)
def clean(self, value):
"""
@@ -137,8 +139,8 @@ DEFAULT_DATE_INPUT_FORMATS = (
)
class DateField(Field):
- def __init__(self, input_formats=None, required=True, widget=None, label=None, initial=None):
- super(DateField, self).__init__(required, widget, label, initial)
+ def __init__(self, input_formats=None, *args, **kwargs):
+ super(DateField, self).__init__(*args, **kwargs)
self.input_formats = input_formats or DEFAULT_DATE_INPUT_FORMATS
def clean(self, value):
@@ -166,8 +168,8 @@ DEFAULT_TIME_INPUT_FORMATS = (
)
class TimeField(Field):
- def __init__(self, input_formats=None, required=True, widget=None, label=None, initial=None):
- super(TimeField, self).__init__(required, widget, label, initial)
+ def __init__(self, input_formats=None, *args, **kwargs):
+ super(TimeField, self).__init__(*args, **kwargs)
self.input_formats = input_formats or DEFAULT_TIME_INPUT_FORMATS
def clean(self, value):
@@ -200,8 +202,8 @@ DEFAULT_DATETIME_INPUT_FORMATS = (
)
class DateTimeField(Field):
- def __init__(self, input_formats=None, required=True, widget=None, label=None, initial=None):
- super(DateTimeField, self).__init__(required, widget, label, initial)
+ def __init__(self, input_formats=None, *args, **kwargs):
+ super(DateTimeField, self).__init__(*args, **kwargs)
self.input_formats = input_formats or DEFAULT_DATETIME_INPUT_FORMATS
def clean(self, value):
@@ -224,14 +226,13 @@ class DateTimeField(Field):
raise ValidationError(gettext(u'Enter a valid date/time.'))
class RegexField(Field):
- def __init__(self, regex, max_length=None, min_length=None, error_message=None,
- required=True, widget=None, label=None, initial=None):
+ def __init__(self, regex, max_length=None, min_length=None, error_message=None, *args, **kwargs):
"""
regex can be either a string or a compiled regular expression object.
error_message is an optional error message to use, if
'Enter a valid value' is too generic for you.
"""
- super(RegexField, self).__init__(required, widget, label, initial)
+ super(RegexField, self).__init__(*args, **kwargs)
if isinstance(regex, basestring):
regex = re.compile(regex)
self.regex = regex
@@ -263,8 +264,9 @@ email_re = re.compile(
r')@(?:[A-Z0-9-]+\.)+[A-Z]{2,6}$', re.IGNORECASE) # domain
class EmailField(RegexField):
- def __init__(self, max_length=None, min_length=None, required=True, widget=None, label=None, initial=None):
- RegexField.__init__(self, email_re, max_length, min_length, gettext(u'Enter a valid e-mail address.'), required, widget, label, initial)
+ def __init__(self, max_length=None, min_length=None, *args, **kwargs):
+ RegexField.__init__(self, email_re, max_length, min_length,
+ gettext(u'Enter a valid e-mail address.'), *args, **kwargs)
url_re = re.compile(
r'^https?://' # http:// or https://
@@ -280,9 +282,9 @@ except ImportError:
URL_VALIDATOR_USER_AGENT = 'Django (http://www.djangoproject.com/)'
class URLField(RegexField):
- def __init__(self, max_length=None, min_length=None, required=True, verify_exists=False, widget=None, label=None,
- initial=None, validator_user_agent=URL_VALIDATOR_USER_AGENT):
- super(URLField, self).__init__(url_re, max_length, min_length, gettext(u'Enter a valid URL.'), required, widget, label, initial)
+ def __init__(self, max_length=None, min_length=None, verify_exists=False,
+ validator_user_agent=URL_VALIDATOR_USER_AGENT, *args, **kwargs):
+ super(URLField, self).__init__(url_re, max_length, min_length, gettext(u'Enter a valid URL.'), *args, **kwargs)
self.verify_exists = verify_exists
self.user_agent = validator_user_agent
@@ -328,10 +330,8 @@ class NullBooleanField(BooleanField):
return {True: True, False: False}.get(value, None)
class ChoiceField(Field):
- def __init__(self, choices=(), required=True, widget=Select, label=None, initial=None):
- if isinstance(widget, type):
- widget = widget()
- super(ChoiceField, self).__init__(required, widget, label, initial)
+ def __init__(self, choices=(), required=True, widget=Select, label=None, initial=None, help_text=None):
+ super(ChoiceField, self).__init__(required, widget, label, initial, help_text)
self.choices = choices
def _get_choices(self):
@@ -362,8 +362,8 @@ class ChoiceField(Field):
class MultipleChoiceField(ChoiceField):
hidden_widget = MultipleHiddenInput
- def __init__(self, choices=(), required=True, widget=SelectMultiple, label=None, initial=None):
- super(MultipleChoiceField, self).__init__(choices, required, widget, label, initial)
+ def __init__(self, choices=(), required=True, widget=SelectMultiple, label=None, initial=None, help_text=None):
+ super(MultipleChoiceField, self).__init__(choices, required, widget, label, initial, help_text)
def clean(self, value):
"""
@@ -390,8 +390,8 @@ class ComboField(Field):
"""
A Field whose clean() method calls multiple Field clean() methods.
"""
- def __init__(self, fields=(), required=True, widget=None, label=None, initial=None):
- super(ComboField, self).__init__(required, widget, label, initial)
+ def __init__(self, fields=(), *args, **kwargs):
+ super(ComboField, self).__init__(*args, **kwargs)
# Set 'required' to False on the individual fields, because the
# required validation will be handled by ComboField, not by those
# individual fields.
@@ -425,8 +425,8 @@ class MultiValueField(Field):
You'll probably want to use this with MultiWidget.
"""
- def __init__(self, fields=(), required=True, widget=None, label=None, initial=None):
- super(MultiValueField, self).__init__(required, widget, label, initial)
+ def __init__(self, fields=(), *args, **kwargs):
+ super(MultiValueField, self).__init__(*args, **kwargs)
# Set 'required' to False on the individual fields, because the
# required validation will be handled by MultiValueField, not by those
# individual fields.
@@ -481,9 +481,9 @@ class MultiValueField(Field):
raise NotImplementedError('Subclasses must implement this method.')
class SplitDateTimeField(MultiValueField):
- def __init__(self, required=True, widget=None, label=None, initial=None):
+ def __init__(self, *args, **kwargs):
fields = (DateField(), TimeField())
- super(SplitDateTimeField, self).__init__(fields, required, widget, label, initial)
+ super(SplitDateTimeField, self).__init__(fields, *args, **kwargs)
def compress(self, data_list):
if data_list:
diff --git a/django/newforms/forms.py b/django/newforms/forms.py
index 1724a5a69f..7e29941bef 100644
--- a/django/newforms/forms.py
+++ b/django/newforms/forms.py
@@ -26,12 +26,15 @@ class SortedDictFromList(SortedDict):
self.keyOrder = [d[0] for d in data]
dict.__init__(self, dict(data))
+ def copy(self):
+ return SortedDictFromList(self.items())
+
class DeclarativeFieldsMetaclass(type):
- "Metaclass that converts Field attributes to a dictionary called 'fields'."
+ "Metaclass that converts Field attributes to a dictionary called 'base_fields'."
def __new__(cls, name, bases, attrs):
fields = [(field_name, attrs.pop(field_name)) for field_name, obj in attrs.items() if isinstance(obj, Field)]
fields.sort(lambda x, y: cmp(x[1].creation_counter, y[1].creation_counter))
- attrs['fields'] = SortedDictFromList(fields)
+ attrs['base_fields'] = SortedDictFromList(fields)
return type.__new__(cls, name, bases, attrs)
class BaseForm(StrAndUnicode):
@@ -46,6 +49,12 @@ class BaseForm(StrAndUnicode):
self.prefix = prefix
self.initial = initial or {}
self.__errors = None # Stores the errors after clean() has been called.
+ # The base_fields class attribute is the *class-wide* definition of
+ # fields. Because a particular *instance* of the class might want to
+ # alter self.fields, we create self.fields here by copying base_fields.
+ # Instances should always modify self.fields; they should not modify
+ # self.base_fields.
+ self.fields = self.base_fields.copy()
def __unicode__(self):
return self.as_table()
@@ -85,7 +94,7 @@ class BaseForm(StrAndUnicode):
"""
return self.prefix and ('%s-%s' % (self.prefix, field_name)) or field_name
- def _html_output(self, normal_row, error_row, row_ender, errors_on_separate_row):
+ def _html_output(self, normal_row, error_row, row_ender, help_text_html, errors_on_separate_row):
"Helper function for outputting HTML. Used by as_table(), as_ul(), as_p()."
top_errors = self.non_field_errors() # Errors that should be displayed above all fields.
output, hidden_fields = [], []
@@ -100,7 +109,11 @@ class BaseForm(StrAndUnicode):
if errors_on_separate_row and bf_errors:
output.append(error_row % bf_errors)
label = bf.label and bf.label_tag(escape(bf.label + ':')) or ''
- output.append(normal_row % {'errors': bf_errors, 'label': label, 'field': unicode(bf)})
+ if field.help_text:
+ help_text = help_text_html % field.help_text
+ else:
+ help_text = u''
+ output.append(normal_row % {'errors': bf_errors, 'label': label, 'field': unicode(bf), 'help_text': help_text})
if top_errors:
output.insert(0, error_row % top_errors)
if hidden_fields: # Insert any hidden fields in the last row.
@@ -115,15 +128,15 @@ class BaseForm(StrAndUnicode):
def as_table(self):
"Returns this form rendered as HTML
s -- excluding the
."
- return self._html_output(u'
%(label)s
%(errors)s%(field)s
', u'
%s
', '', False)
+ return self._html_output(u'
%(label)s
%(errors)s%(field)s%(help_text)s
', u'
%s
', '', u' %s', False)
def as_ul(self):
"Returns this form rendered as HTML
s -- excluding the
."
- return self._html_output(u'
%(errors)s%(label)s %(field)s
', u'
%s
', '', False)
+ return self._html_output(u'
%(errors)s%(label)s %(field)s%(help_text)s
', u'
%s
', '', u' %s', False)
def as_p(self):
"Returns this form rendered as HTML
s."
- return self._html_output(u'
%(label)s %(field)s
', u'
%s
', '
', True)
+ return self._html_output(u'
%(label)s %(field)s%(help_text)s
', u'
%s
', '', u' %s', True)
def non_field_errors(self):
"""
diff --git a/django/newforms/models.py b/django/newforms/models.py
index 819e70d775..9bd6a3ff83 100644
--- a/django/newforms/models.py
+++ b/django/newforms/models.py
@@ -15,10 +15,7 @@ def model_save(self, commit=True):
"""
if self.errors:
raise ValueError("The %s could not be created because the data didn't validate." % self._model._meta.object_name)
- obj = self._model(**self.clean_data)
- if commit:
- obj.save()
- return obj
+ return save_instance(self, self._model(), commit)
def save_instance(form, instance, commit=True):
"""
@@ -33,12 +30,18 @@ def save_instance(form, instance, commit=True):
if form.errors:
raise ValueError("The %s could not be changed because the data didn't validate." % opts.object_name)
clean_data = form.clean_data
- for f in opts.fields + opts.many_to_many:
+ for f in opts.fields:
if isinstance(f, models.AutoField):
continue
setattr(instance, f.attname, clean_data[f.name])
if commit:
instance.save()
+ for f in opts.many_to_many:
+ setattr(instance, f.attname, getattr(instance, f.attname).model.objects.filter(pk__in = clean_data[f.name]))
+ # GOTCHA: If many-to-many data is given and commit=False, the many-to-many
+ # data will be lost. This happens because a many-to-many options cannot be
+ # set on an object until after it's saved. Maybe we should raise an
+ # exception in that case.
return instance
def make_instance_save(instance):
@@ -64,7 +67,7 @@ def form_for_model(model, form=BaseForm, formfield_callback=lambda f: f.formfiel
if formfield:
field_list.append((f.name, formfield))
fields = SortedDictFromList(field_list)
- return type(opts.object_name + 'Form', (form,), {'fields': fields, '_model': model, 'save': model_save})
+ return type(opts.object_name + 'Form', (form,), {'base_fields': fields, '_model': model, 'save': model_save})
def form_for_instance(instance, form=BaseForm, formfield_callback=lambda f, **kwargs: f.formfield(**kwargs)):
"""
@@ -87,9 +90,9 @@ def form_for_instance(instance, form=BaseForm, formfield_callback=lambda f, **kw
field_list.append((f.name, formfield))
fields = SortedDictFromList(field_list)
return type(opts.object_name + 'InstanceForm', (form,),
- {'fields': fields, '_model': model, 'save': make_instance_save(instance)})
+ {'base_fields': fields, '_model': model, 'save': make_instance_save(instance)})
def form_for_fields(field_list):
"Returns a Form class for the given list of Django database field instances."
fields = SortedDictFromList([(f.name, f.formfield()) for f in field_list])
- return type('FormForFields', (BaseForm,), {'fields': fields})
+ return type('FormForFields', (BaseForm,), {'base_fields': fields})
diff --git a/django/newforms/widgets.py b/django/newforms/widgets.py
index c71810465e..585e12cc18 100644
--- a/django/newforms/widgets.py
+++ b/django/newforms/widgets.py
@@ -136,9 +136,11 @@ class CheckboxInput(Widget):
class Select(Widget):
def __init__(self, attrs=None, choices=()):
- # choices can be any iterable
self.attrs = attrs or {}
- self.choices = choices
+ # choices can be any iterable, but we may need to render this widget
+ # multiple times. Thus, collapse it into a list so it can be consumed
+ # more than once.
+ self.choices = list(choices)
def render(self, name, value, attrs=None, choices=()):
if value is None: value = ''
@@ -256,11 +258,16 @@ class RadioSelect(Select):
class CheckboxSelectMultiple(SelectMultiple):
def render(self, name, value, attrs=None, choices=()):
if value is None: value = []
+ has_id = attrs and attrs.has_key('id')
final_attrs = self.build_attrs(attrs, name=name)
output = [u'
']
str_values = set([smart_unicode(v) for v in value]) # Normalize to strings.
- cb = CheckboxInput(final_attrs, check_test=lambda value: value in str_values)
- for option_value, option_label in chain(self.choices, choices):
+ for i, (option_value, option_label) in enumerate(chain(self.choices, choices)):
+ # If an ID attribute was given, add a numeric index as a suffix,
+ # so that the checkboxes don't all have the same ID attribute.
+ if has_id:
+ final_attrs = dict(final_attrs, id='%s_%s' % (attrs['id'], i))
+ cb = CheckboxInput(final_attrs, check_test=lambda value: value in str_values)
option_value = smart_unicode(option_value)
rendered_cb = cb.render(name, option_value)
output.append(u'' % (rendered_cb, escape(smart_unicode(option_label))))
diff --git a/docs/newforms.txt b/docs/newforms.txt
index aeed33752a..063f686ed5 100644
--- a/docs/newforms.txt
+++ b/docs/newforms.txt
@@ -739,6 +739,38 @@ validation if a particular field's value is not given. ``initial`` values are
The ``widget`` argument lets you specify a ``Widget`` class to use when
rendering this ``Field``. See _`Widgets` below for more information.
+``help_text``
+~~~~~~~~~~~~~
+
+The ``help_text`` argument lets you specify descriptive text for this
+``Field``. If you provide ``help_text``, it will be displayed next to the
+``Field`` when the ``Field`` is rendered in a ``Form``.
+
+Here's a full example ``Form`` that implements ``help_text`` for two of its
+fields. We've specified ``auto_id=False`` to simplify the output::
+
+ >>> class HelpTextContactForm(forms.Form):
+ ... subject = forms.CharField(max_length=100, help_text='100 characters max.')
+ ... message = forms.CharField()
+ ... sender = forms.EmailField(help_text='A valid e-mail address, please.')
+ ... cc_myself = forms.BooleanField()
+ >>> f = HelpTextContactForm(auto_id=False)
+ >>> print f.as_table()
+
Subject:
100 characters max.
+
Message:
+
Sender:
A valid e-mail address, please.
+
Cc myself:
+ >>> print f.as_ul()
+
Subject: 100 characters max.
+
Message:
+
Sender: A valid e-mail address, please.
+
Cc myself:
+ >>> print f.as_p()
+
Subject: 100 characters max.
+
Message:
+
Sender: A valid e-mail address, please.
+
Cc myself:
+
Dynamic initial values
----------------------
diff --git a/tests/modeltests/model_forms/models.py b/tests/modeltests/model_forms/models.py
index 620565721c..81a7ec2abf 100644
--- a/tests/modeltests/model_forms/models.py
+++ b/tests/modeltests/model_forms/models.py
@@ -224,6 +224,47 @@ Add some categories and test the many-to-many form output.
+>>> f = TestArticleForm({'headline': u'New headline', 'pub_date': u'1988-01-04',
+... 'writer': u'1', 'article': u'Hello.', 'categories': [u'1', u'2']})
+>>> new_art = f.save()
+>>> new_art.id
+1
+>>> new_art = Article.objects.get(id=1)
+>>> new_art.categories.all()
+[, ]
+
+Now, submit form data with no categories. This deletes the existing categories.
+>>> f = TestArticleForm({'headline': u'New headline', 'pub_date': u'1988-01-04',
+... 'writer': u'1', 'article': u'Hello.'})
+>>> new_art = f.save()
+>>> new_art.id
+1
+>>> new_art = Article.objects.get(id=1)
+>>> new_art.categories.all()
+[]
+
+Create a new article, with categories, via the form.
+>>> ArticleForm = form_for_model(Article)
+>>> f = ArticleForm({'headline': u'The walrus was Paul', 'pub_date': u'1967-11-01',
+... 'writer': u'1', 'article': u'Test.', 'categories': [u'1', u'2']})
+>>> new_art = f.save()
+>>> new_art.id
+2
+>>> new_art = Article.objects.get(id=2)
+>>> new_art.categories.all()
+[, ]
+
+Create a new article, with no categories, via the form.
+>>> ArticleForm = form_for_model(Article)
+>>> f = ArticleForm({'headline': u'The walrus was Paul', 'pub_date': u'1967-11-01',
+... 'writer': u'1', 'article': u'Test.'})
+>>> new_art = f.save()
+>>> new_art.id
+3
+>>> new_art = Article.objects.get(id=3)
+>>> new_art.categories.all()
+[]
+
Here, we define a custom Form. Because it happens to have the same fields as
the Category model, we can use save_instance() to apply its changes to an
existing Category instance.
diff --git a/tests/regressiontests/forms/tests.py b/tests/regressiontests/forms/tests.py
index 95e8b59c01..20a1937f56 100644
--- a/tests/regressiontests/forms/tests.py
+++ b/tests/regressiontests/forms/tests.py
@@ -336,6 +336,26 @@ If 'choices' is passed to both the constructor and render(), then they'll both b
>>> w.render('email', 'ŠĐĆŽćžšđ', choices=[('ŠĐĆŽćžšđ', 'ŠĐabcĆŽćžšđ'), ('ćžšđ', 'abcćžšđ')])
u''
+If choices is passed to the constructor and is a generator, it can be iterated
+over multiple times without getting consumed:
+>>> w = Select(choices=get_choices())
+>>> print w.render('num', 2)
+
+>>> print w.render('num', 3)
+
+
# NullBooleanSelect Widget ####################################################
>>> w = NullBooleanSelect()
@@ -2129,6 +2149,16 @@ MultipleChoiceField can also be used with the CheckboxSelectMultiple widget.
+Regarding auto_id, CheckboxSelectMultiple is a special case. Each checkbox
+gets a distinct ID, formed by appending an underscore plus the checkbox's
+zero-based index.
+>>> f = SongForm(auto_id='%s_id')
+>>> print f['composers']
+
+
+
+
+
Data for a MultipleChoiceField should be a list. QueryDict and MultiValueDict
conveniently work with this.
>>> data = {'name': 'Yesterday', 'composers': ['J', 'P']}
@@ -2247,6 +2277,8 @@ Form.clean() is required to return a dictionary of all clean data.
>>> f.clean_data
{'username': u'adrian', 'password1': u'foo', 'password2': u'foo'}
+# Dynamic construction ########################################################
+
It's possible to construct a Form dynamically by adding to the self.fields
dictionary in __init__(). Don't forget to call Form.__init__() within the
subclass' __init__().
@@ -2262,6 +2294,46 @@ subclass' __init__().
Last name:
Birthday:
+Instances of a dynamic Form do not persist fields from one Form instance to
+the next.
+>>> class MyForm(Form):
+... def __init__(self, data=None, auto_id=False, field_list=[]):
+... Form.__init__(self, data, auto_id)
+... for field in field_list:
+... self.fields[field[0]] = field[1]
+>>> field_list = [('field1', CharField()), ('field2', CharField())]
+>>> my_form = MyForm(field_list=field_list)
+>>> print my_form
+
+
HiddenInput widgets are displayed differently in the as_table(), as_ul()
and as_p() output of a Form -- their verbose names are not displayed, and a
separate row is not displayed. They're displayed in the last row of the
@@ -2538,6 +2610,41 @@ then the latter will get precedence.
Username:
Password:
+# Help text ###################################################################
+
+You can specify descriptive text for a field by using the 'help_text' argument
+to a Field class. This help text is displayed when a Form is rendered.
+>>> class UserRegistration(Form):
+... username = CharField(max_length=10, help_text='e.g., user@example.com')
+... password = CharField(widget=PasswordInput, help_text='Choose wisely.')
+>>> p = UserRegistration(auto_id=False)
+>>> print p.as_ul()
+
Username: e.g., user@example.com
+
Password: Choose wisely.
+>>> print p.as_p()
+
Username: e.g., user@example.com
+
Password: Choose wisely.
+>>> print p.as_table()
+
Username:
e.g., user@example.com
+
Password:
Choose wisely.
+
+The help text is displayed whether or not data is provided for the form.
+>>> p = UserRegistration({'username': u'foo'}, auto_id=False)
+>>> print p.as_ul()
+
Username: e.g., user@example.com
+
This field is required.
Password: Choose wisely.
+
+help_text is not displayed for hidden fields. It can be used for documentation
+purposes, though.
+>>> class UserRegistration(Form):
+... username = CharField(max_length=10, help_text='e.g., user@example.com')
+... password = CharField(widget=PasswordInput)
+... next = CharField(widget=HiddenInput, initial='/', help_text='Redirect destination')
+>>> p = UserRegistration(auto_id=False)
+>>> print p.as_ul()
+
Username: e.g., user@example.com
+
Password:
+
# Forms with prefixes #########################################################
Sometimes it's necessary to have multiple forms display on the same HTML page,