Ticket #4975: label_colon_removal.patch

File label_colon_removal.patch, 90.3 KB (added by Vincent Foley, 17 years ago)
  • django/newforms/forms.py

     
    129129                    output.append(error_row % force_unicode(bf_errors))
    130130                if bf.label:
    131131                    label = escape(force_unicode(bf.label))
    132                     # Only add a colon if the label does not end in punctuation.
    133                     if label[-1] not in ':?.!':
    134                         label += ':'
    135132                    label = bf.label_tag(label) or ''
    136133                else:
    137134                    label = ''
  • tests/modeltests/model_forms/models.py

     
    8080>>> CategoryForm = form_for_model(Category)
    8181>>> f = CategoryForm()
    8282>>> print f
    83 <tr><th><label for="id_name">Name:</label></th><td><input id="id_name" type="text" name="name" maxlength="20" /></td></tr>
    84 <tr><th><label for="id_slug">Slug:</label></th><td><input id="id_slug" type="text" name="slug" maxlength="20" /></td></tr>
    85 <tr><th><label for="id_url">The URL:</label></th><td><input id="id_url" type="text" name="url" maxlength="40" /></td></tr>
     83<tr><th><label for="id_name">Name</label></th><td><input id="id_name" type="text" name="name" maxlength="20" /></td></tr>
     84<tr><th><label for="id_slug">Slug</label></th><td><input id="id_slug" type="text" name="slug" maxlength="20" /></td></tr>
     85<tr><th><label for="id_url">The URL</label></th><td><input id="id_url" type="text" name="url" maxlength="40" /></td></tr>
    8686>>> print f.as_ul()
    87 <li><label for="id_name">Name:</label> <input id="id_name" type="text" name="name" maxlength="20" /></li>
    88 <li><label for="id_slug">Slug:</label> <input id="id_slug" type="text" name="slug" maxlength="20" /></li>
    89 <li><label for="id_url">The URL:</label> <input id="id_url" type="text" name="url" maxlength="40" /></li>
     87<li><label for="id_name">Name</label> <input id="id_name" type="text" name="name" maxlength="20" /></li>
     88<li><label for="id_slug">Slug</label> <input id="id_slug" type="text" name="slug" maxlength="20" /></li>
     89<li><label for="id_url">The URL</label> <input id="id_url" type="text" name="url" maxlength="40" /></li>
    9090>>> print f['name']
    9191<input id="id_name" type="text" name="name" maxlength="20" />
    9292
    9393>>> f = CategoryForm(auto_id=False)
    9494>>> print f.as_ul()
    95 <li>Name: <input type="text" name="name" maxlength="20" /></li>
    96 <li>Slug: <input type="text" name="slug" maxlength="20" /></li>
    97 <li>The URL: <input type="text" name="url" maxlength="40" /></li>
     95<li>Name <input type="text" name="name" maxlength="20" /></li>
     96<li>Slug <input type="text" name="slug" maxlength="20" /></li>
     97<li>The URL <input type="text" name="url" maxlength="40" /></li>
    9898
    9999>>> f = CategoryForm({'name': 'Entertainment', 'slug': 'entertainment', 'url': 'entertainment'})
    100100>>> f.is_valid()
     
    164164>>> ArticleForm = form_for_model(Article)
    165165>>> f = ArticleForm(auto_id=False)
    166166>>> print f
    167 <tr><th>Headline:</th><td><input type="text" name="headline" maxlength="50" /></td></tr>
    168 <tr><th>Slug:</th><td><input type="text" name="slug" maxlength="50" /></td></tr>
    169 <tr><th>Pub date:</th><td><input type="text" name="pub_date" /></td></tr>
    170 <tr><th>Writer:</th><td><select name="writer">
     167<tr><th>Headline</th><td><input type="text" name="headline" maxlength="50" /></td></tr>
     168<tr><th>Slug</th><td><input type="text" name="slug" maxlength="50" /></td></tr>
     169<tr><th>Pub date</th><td><input type="text" name="pub_date" /></td></tr>
     170<tr><th>Writer</th><td><select name="writer">
    171171<option value="" selected="selected">---------</option>
    172172<option value="1">Mike Royko</option>
    173173<option value="2">Bob Woodward</option>
    174174</select></td></tr>
    175 <tr><th>Article:</th><td><textarea rows="10" cols="40" name="article"></textarea></td></tr>
    176 <tr><th>Status:</th><td><select name="status">
     175<tr><th>Article</th><td><textarea rows="10" cols="40" name="article"></textarea></td></tr>
     176<tr><th>Status</th><td><select name="status">
    177177<option value="" selected="selected">---------</option>
    178178<option value="1">Draft</option>
    179179<option value="2">Pending</option>
    180180<option value="3">Live</option>
    181181</select></td></tr>
    182 <tr><th>Categories:</th><td><select multiple="multiple" name="categories">
     182<tr><th>Categories</th><td><select multiple="multiple" name="categories">
    183183<option value="1">Entertainment</option>
    184184<option value="2">It&#39;s a test</option>
    185185<option value="3">Third test</option>
     
    194194>>> PartialArticleForm = form_for_model(Article, fields=('headline','pub_date'))
    195195>>> f = PartialArticleForm(auto_id=False)
    196196>>> print f
    197 <tr><th>Headline:</th><td><input type="text" name="headline" maxlength="50" /></td></tr>
    198 <tr><th>Pub date:</th><td><input type="text" name="pub_date" /></td></tr>
     197<tr><th>Headline</th><td><input type="text" name="headline" maxlength="50" /></td></tr>
     198<tr><th>Pub date</th><td><input type="text" name="pub_date" /></td></tr>
    199199
    200200You can pass a custom Form class to form_for_model. Make sure it's a
    201201subclass of BaseForm, not Form.
     
    214214>>> RoykoForm = form_for_instance(w)
    215215>>> f = RoykoForm(auto_id=False)
    216216>>> print f
    217 <tr><th>Name:</th><td><input type="text" name="name" value="Mike Royko" maxlength="50" /><br />Use both first and last names.</td></tr>
     217<tr><th>Name</th><td><input type="text" name="name" value="Mike Royko" maxlength="50" /><br />Use both first and last names.</td></tr>
    218218
    219219>>> art = Article(headline='Test article', slug='test-article', pub_date=datetime.date(1988, 1, 4), writer=w, article='Hello.')
    220220>>> art.save()
     
    223223>>> TestArticleForm = form_for_instance(art)
    224224>>> f = TestArticleForm(auto_id=False)
    225225>>> print f.as_ul()
    226 <li>Headline: <input type="text" name="headline" value="Test article" maxlength="50" /></li>
    227 <li>Slug: <input type="text" name="slug" value="test-article" maxlength="50" /></li>
    228 <li>Pub date: <input type="text" name="pub_date" value="1988-01-04" /></li>
    229 <li>Writer: <select name="writer">
     226<li>Headline <input type="text" name="headline" value="Test article" maxlength="50" /></li>
     227<li>Slug <input type="text" name="slug" value="test-article" maxlength="50" /></li>
     228<li>Pub date <input type="text" name="pub_date" value="1988-01-04" /></li>
     229<li>Writer <select name="writer">
    230230<option value="">---------</option>
    231231<option value="1" selected="selected">Mike Royko</option>
    232232<option value="2">Bob Woodward</option>
    233233</select></li>
    234 <li>Article: <textarea rows="10" cols="40" name="article">Hello.</textarea></li>
    235 <li>Status: <select name="status">
     234<li>Article <textarea rows="10" cols="40" name="article">Hello.</textarea></li>
     235<li>Status <select name="status">
    236236<option value="" selected="selected">---------</option>
    237237<option value="1">Draft</option>
    238238<option value="2">Pending</option>
    239239<option value="3">Live</option>
    240240</select></li>
    241 <li>Categories: <select multiple="multiple" name="categories">
     241<li>Categories <select multiple="multiple" name="categories">
    242242<option value="1">Entertainment</option>
    243243<option value="2">It&#39;s a test</option>
    244244<option value="3">Third test</option>
     
    258258>>> PartialArticleForm = form_for_instance(art, fields=('headline', 'slug', 'pub_date'))
    259259>>> f = PartialArticleForm({'headline': u'New headline', 'slug': 'new-headline', 'pub_date': u'1988-01-04'}, auto_id=False)
    260260>>> print f.as_ul()
    261 <li>Headline: <input type="text" name="headline" value="New headline" maxlength="50" /></li>
    262 <li>Slug: <input type="text" name="slug" value="new-headline" maxlength="50" /></li>
    263 <li>Pub date: <input type="text" name="pub_date" value="1988-01-04" /></li>
     261<li>Headline <input type="text" name="headline" value="New headline" maxlength="50" /></li>
     262<li>Slug <input type="text" name="slug" value="new-headline" maxlength="50" /></li>
     263<li>Pub date <input type="text" name="pub_date" value="1988-01-04" /></li>
    264264>>> f.is_valid()
    265265True
    266266>>> new_art = f.save()
     
    279279>>> TestArticleForm = form_for_instance(new_art)
    280280>>> f = TestArticleForm(auto_id=False)
    281281>>> print f.as_ul()
    282 <li>Headline: <input type="text" name="headline" value="New headline" maxlength="50" /></li>
    283 <li>Slug: <input type="text" name="slug" value="new-headline" maxlength="50" /></li>
    284 <li>Pub date: <input type="text" name="pub_date" value="1988-01-04" /></li>
    285 <li>Writer: <select name="writer">
     282<li>Headline <input type="text" name="headline" value="New headline" maxlength="50" /></li>
     283<li>Slug <input type="text" name="slug" value="new-headline" maxlength="50" /></li>
     284<li>Pub date <input type="text" name="pub_date" value="1988-01-04" /></li>
     285<li>Writer <select name="writer">
    286286<option value="">---------</option>
    287287<option value="1" selected="selected">Mike Royko</option>
    288288<option value="2">Bob Woodward</option>
    289289</select></li>
    290 <li>Article: <textarea rows="10" cols="40" name="article">Hello.</textarea></li>
    291 <li>Status: <select name="status">
     290<li>Article <textarea rows="10" cols="40" name="article">Hello.</textarea></li>
     291<li>Status <select name="status">
    292292<option value="" selected="selected">---------</option>
    293293<option value="1">Draft</option>
    294294<option value="2">Pending</option>
    295295<option value="3">Live</option>
    296296</select></li>
    297 <li>Categories: <select multiple="multiple" name="categories">
     297<li>Categories <select multiple="multiple" name="categories">
    298298<option value="1" selected="selected">Entertainment</option>
    299299<option value="2">It&#39;s a test</option>
    300300<option value="3">Third test</option>
     
    387387>>> ArticleForm = form_for_model(Article)
    388388>>> f = ArticleForm(auto_id=False)
    389389>>> print f.as_ul()
    390 <li>Headline: <input type="text" name="headline" maxlength="50" /></li>
    391 <li>Slug: <input type="text" name="slug" maxlength="50" /></li>
    392 <li>Pub date: <input type="text" name="pub_date" /></li>
    393 <li>Writer: <select name="writer">
     390<li>Headline <input type="text" name="headline" maxlength="50" /></li>
     391<li>Slug <input type="text" name="slug" maxlength="50" /></li>
     392<li>Pub date <input type="text" name="pub_date" /></li>
     393<li>Writer <select name="writer">
    394394<option value="" selected="selected">---------</option>
    395395<option value="1">Mike Royko</option>
    396396<option value="2">Bob Woodward</option>
    397397</select></li>
    398 <li>Article: <textarea rows="10" cols="40" name="article"></textarea></li>
    399 <li>Status: <select name="status">
     398<li>Article <textarea rows="10" cols="40" name="article"></textarea></li>
     399<li>Status <select name="status">
    400400<option value="" selected="selected">---------</option>
    401401<option value="1">Draft</option>
    402402<option value="2">Pending</option>
    403403<option value="3">Live</option>
    404404</select></li>
    405 <li>Categories: <select multiple="multiple" name="categories">
     405<li>Categories <select multiple="multiple" name="categories">
    406406<option value="1">Entertainment</option>
    407407<option value="2">It&#39;s a test</option>
    408408<option value="3">Third</option>
     
    412412>>> Writer.objects.create(name='Carl Bernstein')
    413413<Writer: Carl Bernstein>
    414414>>> print f.as_ul()
    415 <li>Headline: <input type="text" name="headline" maxlength="50" /></li>
    416 <li>Slug: <input type="text" name="slug" maxlength="50" /></li>
    417 <li>Pub date: <input type="text" name="pub_date" /></li>
    418 <li>Writer: <select name="writer">
     415<li>Headline <input type="text" name="headline" maxlength="50" /></li>
     416<li>Slug <input type="text" name="slug" maxlength="50" /></li>
     417<li>Pub date <input type="text" name="pub_date" /></li>
     418<li>Writer <select name="writer">
    419419<option value="" selected="selected">---------</option>
    420420<option value="1">Mike Royko</option>
    421421<option value="2">Bob Woodward</option>
    422422<option value="3">Carl Bernstein</option>
    423423</select></li>
    424 <li>Article: <textarea rows="10" cols="40" name="article"></textarea></li>
    425 <li>Status: <select name="status">
     424<li>Article <textarea rows="10" cols="40" name="article"></textarea></li>
     425<li>Status <select name="status">
    426426<option value="" selected="selected">---------</option>
    427427<option value="1">Draft</option>
    428428<option value="2">Pending</option>
    429429<option value="3">Live</option>
    430430</select></li>
    431 <li>Categories: <select multiple="multiple" name="categories">
     431<li>Categories <select multiple="multiple" name="categories">
    432432<option value="1">Entertainment</option>
    433433<option value="2">It&#39;s a test</option>
    434434<option value="3">Third</option>
  • tests/regressiontests/forms/tests.py

     
    347347...     somechoice = ChoiceField(choices=chain((('', '-'*9),), [(thing['id'], thing['name']) for thing in things]))
    348348>>> f = SomeForm()
    349349>>> f.as_table()
    350 u'<tr><th><label for="id_somechoice">Somechoice:</label></th><td><select name="somechoice" id="id_somechoice">\n<option value="" selected="selected">---------</option>\n<option value="1">And Boom</option>\n<option value="2">One More Thing!</option>\n</select></td></tr>'
     350u'<tr><th><label for="id_somechoice">Somechoice</label></th><td><select name="somechoice" id="id_somechoice">\n<option value="" selected="selected">---------</option>\n<option value="1">And Boom</option>\n<option value="2">One More Thing!</option>\n</select></td></tr>'
    351351>>> f.as_table()
    352 u'<tr><th><label for="id_somechoice">Somechoice:</label></th><td><select name="somechoice" id="id_somechoice">\n<option value="" selected="selected">---------</option>\n<option value="1">And Boom</option>\n<option value="2">One More Thing!</option>\n</select></td></tr>'
     352u'<tr><th><label for="id_somechoice">Somechoice</label></th><td><select name="somechoice" id="id_somechoice">\n<option value="" selected="selected">---------</option>\n<option value="1">And Boom</option>\n<option value="2">One More Thing!</option>\n</select></td></tr>'
    353353>>> f = SomeForm({'somechoice': 2})
    354354>>> f.as_table()
    355 u'<tr><th><label for="id_somechoice">Somechoice:</label></th><td><select name="somechoice" id="id_somechoice">\n<option value="">---------</option>\n<option value="1">And Boom</option>\n<option value="2" selected="selected">One More Thing!</option>\n</select></td></tr>'
     355u'<tr><th><label for="id_somechoice">Somechoice</label></th><td><select name="somechoice" id="id_somechoice">\n<option value="">---------</option>\n<option value="1">And Boom</option>\n<option value="2" selected="selected">One More Thing!</option>\n</select></td></tr>'
    356356
    357357You can also pass 'choices' to the constructor:
    358358>>> w = Select(choices=[(1, 1), (2, 2), (3, 3)])
     
    20482048Last name Lennon
    20492049Birthday 1940-10-9
    20502050>>> print p
    2051 <tr><th><label for="id_first_name">First name:</label></th><td><input type="text" name="first_name" value="John" id="id_first_name" /></td></tr>
    2052 <tr><th><label for="id_last_name">Last name:</label></th><td><input type="text" name="last_name" value="Lennon" id="id_last_name" /></td></tr>
    2053 <tr><th><label for="id_birthday">Birthday:</label></th><td><input type="text" name="birthday" value="1940-10-9" id="id_birthday" /></td></tr>
     2051<tr><th><label for="id_first_name">First name</label></th><td><input type="text" name="first_name" value="John" id="id_first_name" /></td></tr>
     2052<tr><th><label for="id_last_name">Last name</label></th><td><input type="text" name="last_name" value="Lennon" id="id_last_name" /></td></tr>
     2053<tr><th><label for="id_birthday">Birthday</label></th><td><input type="text" name="birthday" value="1940-10-9" id="id_birthday" /></td></tr>
    20542054
    20552055Empty dictionaries are valid, too.
    20562056>>> p = Person({})
     
    20652065...
    20662066AttributeError: 'Person' object has no attribute 'cleaned_data'
    20672067>>> print p
    2068 <tr><th><label for="id_first_name">First name:</label></th><td><ul class="errorlist"><li>This field is required.</li></ul><input type="text" name="first_name" id="id_first_name" /></td></tr>
    2069 <tr><th><label for="id_last_name">Last name:</label></th><td><ul class="errorlist"><li>This field is required.</li></ul><input type="text" name="last_name" id="id_last_name" /></td></tr>
    2070 <tr><th><label for="id_birthday">Birthday:</label></th><td><ul class="errorlist"><li>This field is required.</li></ul><input type="text" name="birthday" id="id_birthday" /></td></tr>
     2068<tr><th><label for="id_first_name">First name</label></th><td><ul class="errorlist"><li>This field is required.</li></ul><input type="text" name="first_name" id="id_first_name" /></td></tr>
     2069<tr><th><label for="id_last_name">Last name</label></th><td><ul class="errorlist"><li>This field is required.</li></ul><input type="text" name="last_name" id="id_last_name" /></td></tr>
     2070<tr><th><label for="id_birthday">Birthday</label></th><td><ul class="errorlist"><li>This field is required.</li></ul><input type="text" name="birthday" id="id_birthday" /></td></tr>
    20712071>>> print p.as_table()
    2072 <tr><th><label for="id_first_name">First name:</label></th><td><ul class="errorlist"><li>This field is required.</li></ul><input type="text" name="first_name" id="id_first_name" /></td></tr>
    2073 <tr><th><label for="id_last_name">Last name:</label></th><td><ul class="errorlist"><li>This field is required.</li></ul><input type="text" name="last_name" id="id_last_name" /></td></tr>
    2074 <tr><th><label for="id_birthday">Birthday:</label></th><td><ul class="errorlist"><li>This field is required.</li></ul><input type="text" name="birthday" id="id_birthday" /></td></tr>
     2072<tr><th><label for="id_first_name">First name</label></th><td><ul class="errorlist"><li>This field is required.</li></ul><input type="text" name="first_name" id="id_first_name" /></td></tr>
     2073<tr><th><label for="id_last_name">Last name</label></th><td><ul class="errorlist"><li>This field is required.</li></ul><input type="text" name="last_name" id="id_last_name" /></td></tr>
     2074<tr><th><label for="id_birthday">Birthday</label></th><td><ul class="errorlist"><li>This field is required.</li></ul><input type="text" name="birthday" id="id_birthday" /></td></tr>
    20752075>>> print p.as_ul()
    2076 <li><ul class="errorlist"><li>This field is required.</li></ul><label for="id_first_name">First name:</label> <input type="text" name="first_name" id="id_first_name" /></li>
    2077 <li><ul class="errorlist"><li>This field is required.</li></ul><label for="id_last_name">Last name:</label> <input type="text" name="last_name" id="id_last_name" /></li>
    2078 <li><ul class="errorlist"><li>This field is required.</li></ul><label for="id_birthday">Birthday:</label> <input type="text" name="birthday" id="id_birthday" /></li>
     2076<li><ul class="errorlist"><li>This field is required.</li></ul><label for="id_first_name">First name</label> <input type="text" name="first_name" id="id_first_name" /></li>
     2077<li><ul class="errorlist"><li>This field is required.</li></ul><label for="id_last_name">Last name</label> <input type="text" name="last_name" id="id_last_name" /></li>
     2078<li><ul class="errorlist"><li>This field is required.</li></ul><label for="id_birthday">Birthday</label> <input type="text" name="birthday" id="id_birthday" /></li>
    20792079>>> print p.as_p()
    20802080<ul class="errorlist"><li>This field is required.</li></ul>
    2081 <p><label for="id_first_name">First name:</label> <input type="text" name="first_name" id="id_first_name" /></p>
     2081<p><label for="id_first_name">First name</label> <input type="text" name="first_name" id="id_first_name" /></p>
    20822082<ul class="errorlist"><li>This field is required.</li></ul>
    2083 <p><label for="id_last_name">Last name:</label> <input type="text" name="last_name" id="id_last_name" /></p>
     2083<p><label for="id_last_name">Last name</label> <input type="text" name="last_name" id="id_last_name" /></p>
    20842084<ul class="errorlist"><li>This field is required.</li></ul>
    2085 <p><label for="id_birthday">Birthday:</label> <input type="text" name="birthday" id="id_birthday" /></p>
     2085<p><label for="id_birthday">Birthday</label> <input type="text" name="birthday" id="id_birthday" /></p>
    20862086
    20872087If you don't pass any values to the Form's __init__(), or if you pass None,
    20882088the Form will be considered unbound and won't do any validation. Form.errors
     
    20992099...
    21002100AttributeError: 'Person' object has no attribute 'cleaned_data'
    21012101>>> print p
    2102 <tr><th><label for="id_first_name">First name:</label></th><td><input type="text" name="first_name" id="id_first_name" /></td></tr>
    2103 <tr><th><label for="id_last_name">Last name:</label></th><td><input type="text" name="last_name" id="id_last_name" /></td></tr>
    2104 <tr><th><label for="id_birthday">Birthday:</label></th><td><input type="text" name="birthday" id="id_birthday" /></td></tr>
     2102<tr><th><label for="id_first_name">First name</label></th><td><input type="text" name="first_name" id="id_first_name" /></td></tr>
     2103<tr><th><label for="id_last_name">Last name</label></th><td><input type="text" name="last_name" id="id_last_name" /></td></tr>
     2104<tr><th><label for="id_birthday">Birthday</label></th><td><input type="text" name="birthday" id="id_birthday" /></td></tr>
    21052105>>> print p.as_table()
    2106 <tr><th><label for="id_first_name">First name:</label></th><td><input type="text" name="first_name" id="id_first_name" /></td></tr>
    2107 <tr><th><label for="id_last_name">Last name:</label></th><td><input type="text" name="last_name" id="id_last_name" /></td></tr>
    2108 <tr><th><label for="id_birthday">Birthday:</label></th><td><input type="text" name="birthday" id="id_birthday" /></td></tr>
     2106<tr><th><label for="id_first_name">First name</label></th><td><input type="text" name="first_name" id="id_first_name" /></td></tr>
     2107<tr><th><label for="id_last_name">Last name</label></th><td><input type="text" name="last_name" id="id_last_name" /></td></tr>
     2108<tr><th><label for="id_birthday">Birthday</label></th><td><input type="text" name="birthday" id="id_birthday" /></td></tr>
    21092109>>> print p.as_ul()
    2110 <li><label for="id_first_name">First name:</label> <input type="text" name="first_name" id="id_first_name" /></li>
    2111 <li><label for="id_last_name">Last name:</label> <input type="text" name="last_name" id="id_last_name" /></li>
    2112 <li><label for="id_birthday">Birthday:</label> <input type="text" name="birthday" id="id_birthday" /></li>
     2110<li><label for="id_first_name">First name</label> <input type="text" name="first_name" id="id_first_name" /></li>
     2111<li><label for="id_last_name">Last name</label> <input type="text" name="last_name" id="id_last_name" /></li>
     2112<li><label for="id_birthday">Birthday</label> <input type="text" name="birthday" id="id_birthday" /></li>
    21132113>>> print p.as_p()
    2114 <p><label for="id_first_name">First name:</label> <input type="text" name="first_name" id="id_first_name" /></p>
    2115 <p><label for="id_last_name">Last name:</label> <input type="text" name="last_name" id="id_last_name" /></p>
    2116 <p><label for="id_birthday">Birthday:</label> <input type="text" name="birthday" id="id_birthday" /></p>
     2114<p><label for="id_first_name">First name</label> <input type="text" name="first_name" id="id_first_name" /></p>
     2115<p><label for="id_last_name">Last name</label> <input type="text" name="last_name" id="id_last_name" /></p>
     2116<p><label for="id_birthday">Birthday</label> <input type="text" name="birthday" id="id_birthday" /></p>
    21172117
    21182118Unicode values are handled properly.
    21192119>>> p = Person({'first_name': u'John', 'last_name': u'\u0160\u0110\u0106\u017d\u0107\u017e\u0161\u0111', 'birthday': '1940-10-9'})
    21202120>>> p.as_table()
    2121 u'<tr><th><label for="id_first_name">First name:</label></th><td><input type="text" name="first_name" value="John" id="id_first_name" /></td></tr>\n<tr><th><label for="id_last_name">Last name:</label></th><td><input type="text" name="last_name" value="\u0160\u0110\u0106\u017d\u0107\u017e\u0161\u0111" id="id_last_name" /></td></tr>\n<tr><th><label for="id_birthday">Birthday:</label></th><td><input type="text" name="birthday" value="1940-10-9" id="id_birthday" /></td></tr>'
     2121u'<tr><th><label for="id_first_name">First name</label></th><td><input type="text" name="first_name" value="John" id="id_first_name" /></td></tr>\n<tr><th><label for="id_last_name">Last name</label></th><td><input type="text" name="last_name" value="\u0160\u0110\u0106\u017d\u0107\u017e\u0161\u0111" id="id_last_name" /></td></tr>\n<tr><th><label for="id_birthday">Birthday</label></th><td><input type="text" name="birthday" value="1940-10-9" id="id_birthday" /></td></tr>'
    21222122>>> p.as_ul()
    2123 u'<li><label for="id_first_name">First name:</label> <input type="text" name="first_name" value="John" id="id_first_name" /></li>\n<li><label for="id_last_name">Last name:</label> <input type="text" name="last_name" value="\u0160\u0110\u0106\u017d\u0107\u017e\u0161\u0111" id="id_last_name" /></li>\n<li><label for="id_birthday">Birthday:</label> <input type="text" name="birthday" value="1940-10-9" id="id_birthday" /></li>'
     2123u'<li><label for="id_first_name">First name</label> <input type="text" name="first_name" value="John" id="id_first_name" /></li>\n<li><label for="id_last_name">Last name</label> <input type="text" name="last_name" value="\u0160\u0110\u0106\u017d\u0107\u017e\u0161\u0111" id="id_last_name" /></li>\n<li><label for="id_birthday">Birthday</label> <input type="text" name="birthday" value="1940-10-9" id="id_birthday" /></li>'
    21242124>>> p.as_p()
    2125 u'<p><label for="id_first_name">First name:</label> <input type="text" name="first_name" value="John" id="id_first_name" /></p>\n<p><label for="id_last_name">Last name:</label> <input type="text" name="last_name" value="\u0160\u0110\u0106\u017d\u0107\u017e\u0161\u0111" id="id_last_name" /></p>\n<p><label for="id_birthday">Birthday:</label> <input type="text" name="birthday" value="1940-10-9" id="id_birthday" /></p>'
     2125u'<p><label for="id_first_name">First name</label> <input type="text" name="first_name" value="John" id="id_first_name" /></p>\n<p><label for="id_last_name">Last name</label> <input type="text" name="last_name" value="\u0160\u0110\u0106\u017d\u0107\u017e\u0161\u0111" id="id_last_name" /></p>\n<p><label for="id_birthday">Birthday</label> <input type="text" name="birthday" value="1940-10-9" id="id_birthday" /></p>'
    21262126
    21272127>>> p = Person({'last_name': u'Lennon'})
    21282128>>> p.errors
     
    22002200the human-readable labels for a field.
    22012201>>> p = Person(auto_id='%s_id')
    22022202>>> print p.as_table()
    2203 <tr><th><label for="first_name_id">First name:</label></th><td><input type="text" name="first_name" id="first_name_id" /></td></tr>
    2204 <tr><th><label for="last_name_id">Last name:</label></th><td><input type="text" name="last_name" id="last_name_id" /></td></tr>
    2205 <tr><th><label for="birthday_id">Birthday:</label></th><td><input type="text" name="birthday" id="birthday_id" /></td></tr>
     2203<tr><th><label for="first_name_id">First name</label></th><td><input type="text" name="first_name" id="first_name_id" /></td></tr>
     2204<tr><th><label for="last_name_id">Last name</label></th><td><input type="text" name="last_name" id="last_name_id" /></td></tr>
     2205<tr><th><label for="birthday_id">Birthday</label></th><td><input type="text" name="birthday" id="birthday_id" /></td></tr>
    22062206>>> print p.as_ul()
    2207 <li><label for="first_name_id">First name:</label> <input type="text" name="first_name" id="first_name_id" /></li>
    2208 <li><label for="last_name_id">Last name:</label> <input type="text" name="last_name" id="last_name_id" /></li>
    2209 <li><label for="birthday_id">Birthday:</label> <input type="text" name="birthday" id="birthday_id" /></li>
     2207<li><label for="first_name_id">First name</label> <input type="text" name="first_name" id="first_name_id" /></li>
     2208<li><label for="last_name_id">Last name</label> <input type="text" name="last_name" id="last_name_id" /></li>
     2209<li><label for="birthday_id">Birthday</label> <input type="text" name="birthday" id="birthday_id" /></li>
    22102210>>> print p.as_p()
    2211 <p><label for="first_name_id">First name:</label> <input type="text" name="first_name" id="first_name_id" /></p>
    2212 <p><label for="last_name_id">Last name:</label> <input type="text" name="last_name" id="last_name_id" /></p>
    2213 <p><label for="birthday_id">Birthday:</label> <input type="text" name="birthday" id="birthday_id" /></p>
     2211<p><label for="first_name_id">First name</label> <input type="text" name="first_name" id="first_name_id" /></p>
     2212<p><label for="last_name_id">Last name</label> <input type="text" name="last_name" id="last_name_id" /></p>
     2213<p><label for="birthday_id">Birthday</label> <input type="text" name="birthday" id="birthday_id" /></p>
    22142214
    22152215If auto_id is any True value whose str() does not contain '%s', the "id"
    22162216attribute will be the name of the field.
    22172217>>> p = Person(auto_id=True)
    22182218>>> print p.as_ul()
    2219 <li><label for="first_name">First name:</label> <input type="text" name="first_name" id="first_name" /></li>
    2220 <li><label for="last_name">Last name:</label> <input type="text" name="last_name" id="last_name" /></li>
    2221 <li><label for="birthday">Birthday:</label> <input type="text" name="birthday" id="birthday" /></li>
     2219<li><label for="first_name">First name</label> <input type="text" name="first_name" id="first_name" /></li>
     2220<li><label for="last_name">Last name</label> <input type="text" name="last_name" id="last_name" /></li>
     2221<li><label for="birthday">Birthday</label> <input type="text" name="birthday" id="birthday" /></li>
    22222222
    22232223If auto_id is any False value, an "id" attribute won't be output unless it
    22242224was manually entered.
    22252225>>> p = Person(auto_id=False)
    22262226>>> print p.as_ul()
    2227 <li>First name: <input type="text" name="first_name" /></li>
    2228 <li>Last name: <input type="text" name="last_name" /></li>
    2229 <li>Birthday: <input type="text" name="birthday" /></li>
     2227<li>First name <input type="text" name="first_name" /></li>
     2228<li>Last name <input type="text" name="last_name" /></li>
     2229<li>Birthday <input type="text" name="birthday" /></li>
    22302230
    22312231In this example, auto_id is False, but the "id" attribute for the "first_name"
    22322232field is given. Also note that field gets a <label>, while the others don't.
     
    22362236...     birthday = DateField()
    22372237>>> p = PersonNew(auto_id=False)
    22382238>>> print p.as_ul()
    2239 <li><label for="first_name_id">First name:</label> <input type="text" id="first_name_id" name="first_name" /></li>
    2240 <li>Last name: <input type="text" name="last_name" /></li>
    2241 <li>Birthday: <input type="text" name="birthday" /></li>
     2239<li><label for="first_name_id">First name</label> <input type="text" id="first_name_id" name="first_name" /></li>
     2240<li>Last name <input type="text" name="last_name" /></li>
     2241<li>Birthday <input type="text" name="birthday" /></li>
    22422242
    22432243If the "id" attribute is specified in the Form and auto_id is True, the "id"
    22442244attribute in the Form gets precedence.
    22452245>>> p = PersonNew(auto_id=True)
    22462246>>> print p.as_ul()
    2247 <li><label for="first_name_id">First name:</label> <input type="text" id="first_name_id" name="first_name" /></li>
    2248 <li><label for="last_name">Last name:</label> <input type="text" name="last_name" id="last_name" /></li>
    2249 <li><label for="birthday">Birthday:</label> <input type="text" name="birthday" id="birthday" /></li>
     2247<li><label for="first_name_id">First name</label> <input type="text" id="first_name_id" name="first_name" /></li>
     2248<li><label for="last_name">Last name</label> <input type="text" name="last_name" id="last_name" /></li>
     2249<li><label for="birthday">Birthday</label> <input type="text" name="birthday" id="birthday" /></li>
    22502250
    22512251>>> class SignupForm(Form):
    22522252...     email = EmailField()
     
    23942394<li><label><input type="radio" name="language" value="J" /> Java</label></li>
    23952395</ul>
    23962396>>> print f
    2397 <tr><th>Name:</th><td><input type="text" name="name" /></td></tr>
    2398 <tr><th>Language:</th><td><ul>
     2397<tr><th>Name</th><td><input type="text" name="name" /></td></tr>
     2398<tr><th>Language</th><td><ul>
    23992399<li><label><input type="radio" name="language" value="P" /> Python</label></li>
    24002400<li><label><input type="radio" name="language" value="J" /> Java</label></li>
    24012401</ul></td></tr>
    24022402>>> print f.as_ul()
    2403 <li>Name: <input type="text" name="name" /></li>
    2404 <li>Language: <ul>
     2403<li>Name <input type="text" name="name" /></li>
     2404<li>Language <ul>
    24052405<li><label><input type="radio" name="language" value="P" /> Python</label></li>
    24062406<li><label><input type="radio" name="language" value="J" /> Java</label></li>
    24072407</ul></li>
     
    24202420either as_table() or as_ul(), the label for the RadioSelect will point to the
    24212421ID of the *first* radio button.
    24222422>>> print f
    2423 <tr><th><label for="id_name">Name:</label></th><td><input type="text" name="name" id="id_name" /></td></tr>
    2424 <tr><th><label for="id_language_0">Language:</label></th><td><ul>
     2423<tr><th><label for="id_name">Name</label></th><td><input type="text" name="name" id="id_name" /></td></tr>
     2424<tr><th><label for="id_language_0">Language</label></th><td><ul>
    24252425<li><label><input type="radio" id="id_language_0" value="P" name="language" /> Python</label></li>
    24262426<li><label><input type="radio" id="id_language_1" value="J" name="language" /> Java</label></li>
    24272427</ul></td></tr>
    24282428>>> print f.as_ul()
    2429 <li><label for="id_name">Name:</label> <input type="text" name="name" id="id_name" /></li>
    2430 <li><label for="id_language_0">Language:</label> <ul>
     2429<li><label for="id_name">Name</label> <input type="text" name="name" id="id_name" /></li>
     2430<li><label for="id_language_0">Language</label> <ul>
    24312431<li><label><input type="radio" id="id_language_0" value="P" name="language" /> Python</label></li>
    24322432<li><label><input type="radio" id="id_language_1" value="J" name="language" /> Java</label></li>
    24332433</ul></li>
    24342434>>> print f.as_p()
    2435 <p><label for="id_name">Name:</label> <input type="text" name="name" id="id_name" /></p>
    2436 <p><label for="id_language_0">Language:</label> <ul>
     2435<p><label for="id_name">Name</label> <input type="text" name="name" id="id_name" /></p>
     2436<p><label for="id_language_0">Language</label> <ul>
    24372437<li><label><input type="radio" id="id_language_0" value="P" name="language" /> Python</label></li>
    24382438<li><label><input type="radio" id="id_language_1" value="J" name="language" /> Java</label></li>
    24392439</ul></p>
     
    25312531...     composers = MultipleChoiceField(choices=[('J', 'John Lennon'), ('P', 'Paul McCartney')], widget=MultipleHiddenInput)
    25322532>>> f = SongFormHidden(MultiValueDict(dict(name=['Yesterday'], composers=['J', 'P'])), auto_id=False)
    25332533>>> print f.as_ul()
    2534 <li>Name: <input type="text" name="name" value="Yesterday" /><input type="hidden" name="composers" value="J" />
     2534<li>Name <input type="text" name="name" value="Yesterday" /><input type="hidden" name="composers" value="J" />
    25352535<input type="hidden" name="composers" value="P" /></li>
    25362536
    25372537When using CheckboxSelectMultiple, the framework expects a list of input and
     
    25582558
    25592559>>> f = EscapingForm({'special_name': "Nothing to escape"}, auto_id=False)
    25602560>>> print f
    2561 <tr><th>Special name:</th><td><ul class="errorlist"><li>Something&#39;s wrong with &#39;Nothing to escape&#39;</li></ul><input type="text" name="special_name" value="Nothing to escape" /></td></tr>
     2561<tr><th>Special name</th><td><ul class="errorlist"><li>Something&#39;s wrong with &#39;Nothing to escape&#39;</li></ul><input type="text" name="special_name" value="Nothing to escape" /></td></tr>
    25622562>>> f = EscapingForm({'special_name': "Should escape < & > and <script>alert('xss')</script>"}, auto_id=False)
    25632563>>> print f
    2564 <tr><th>Special name:</th><td><ul class="errorlist"><li>Something&#39;s wrong with &#39;Should escape &lt; &amp; &gt; and &lt;script&gt;alert(&#39;xss&#39;)&lt;/script&gt;&#39;</li></ul><input type="text" name="special_name" value="Should escape &lt; &amp; &gt; and &lt;script&gt;alert(&#39;xss&#39;)&lt;/script&gt;" /></td></tr>
     2564<tr><th>Special name</th><td><ul class="errorlist"><li>Something&#39;s wrong with &#39;Should escape &lt; &amp; &gt; and &lt;script&gt;alert(&#39;xss&#39;)&lt;/script&gt;&#39;</li></ul><input type="text" name="special_name" value="Should escape &lt; &amp; &gt; and &lt;script&gt;alert(&#39;xss&#39;)&lt;/script&gt;" /></td></tr>
    25652565
    25662566# Validating multiple fields in relation to another ###########################
    25672567
     
    26152615{}
    26162616>>> f = UserRegistration({}, auto_id=False)
    26172617>>> print f.as_table()
    2618 <tr><th>Username:</th><td><ul class="errorlist"><li>This field is required.</li></ul><input type="text" name="username" maxlength="10" /></td></tr>
    2619 <tr><th>Password1:</th><td><ul class="errorlist"><li>This field is required.</li></ul><input type="password" name="password1" /></td></tr>
    2620 <tr><th>Password2:</th><td><ul class="errorlist"><li>This field is required.</li></ul><input type="password" name="password2" /></td></tr>
     2618<tr><th>Username</th><td><ul class="errorlist"><li>This field is required.</li></ul><input type="text" name="username" maxlength="10" /></td></tr>
     2619<tr><th>Password1</th><td><ul class="errorlist"><li>This field is required.</li></ul><input type="password" name="password1" /></td></tr>
     2620<tr><th>Password2</th><td><ul class="errorlist"><li>This field is required.</li></ul><input type="password" name="password2" /></td></tr>
    26212621>>> f.errors
    26222622{'username': [u'This field is required.'], 'password1': [u'This field is required.'], 'password2': [u'This field is required.']}
    26232623>>> f = UserRegistration({'username': 'adrian', 'password1': 'foo', 'password2': 'bar'}, auto_id=False)
     
    26252625{'__all__': [u'Please make sure your passwords match.']}
    26262626>>> print f.as_table()
    26272627<tr><td colspan="2"><ul class="errorlist"><li>Please make sure your passwords match.</li></ul></td></tr>
    2628 <tr><th>Username:</th><td><input type="text" name="username" value="adrian" maxlength="10" /></td></tr>
    2629 <tr><th>Password1:</th><td><input type="password" name="password1" value="foo" /></td></tr>
    2630 <tr><th>Password2:</th><td><input type="password" name="password2" value="bar" /></td></tr>
     2628<tr><th>Username</th><td><input type="text" name="username" value="adrian" maxlength="10" /></td></tr>
     2629<tr><th>Password1</th><td><input type="password" name="password1" value="foo" /></td></tr>
     2630<tr><th>Password2</th><td><input type="password" name="password2" value="bar" /></td></tr>
    26312631>>> print f.as_ul()
    26322632<li><ul class="errorlist"><li>Please make sure your passwords match.</li></ul></li>
    2633 <li>Username: <input type="text" name="username" value="adrian" maxlength="10" /></li>
    2634 <li>Password1: <input type="password" name="password1" value="foo" /></li>
    2635 <li>Password2: <input type="password" name="password2" value="bar" /></li>
     2633<li>Username <input type="text" name="username" value="adrian" maxlength="10" /></li>
     2634<li>Password1 <input type="password" name="password1" value="foo" /></li>
     2635<li>Password2 <input type="password" name="password2" value="bar" /></li>
    26362636>>> f = UserRegistration({'username': 'adrian', 'password1': 'foo', 'password2': 'foo'}, auto_id=False)
    26372637>>> f.errors
    26382638{}
     
    26522652...         self.fields['birthday'] = DateField()
    26532653>>> p = Person(auto_id=False)
    26542654>>> print p
    2655 <tr><th>First name:</th><td><input type="text" name="first_name" /></td></tr>
    2656 <tr><th>Last name:</th><td><input type="text" name="last_name" /></td></tr>
    2657 <tr><th>Birthday:</th><td><input type="text" name="birthday" /></td></tr>
     2655<tr><th>First name</th><td><input type="text" name="first_name" /></td></tr>
     2656<tr><th>Last name</th><td><input type="text" name="last_name" /></td></tr>
     2657<tr><th>Birthday</th><td><input type="text" name="birthday" /></td></tr>
    26582658
    26592659Instances of a dynamic Form do not persist fields from one Form instance to
    26602660the next.
     
    26662666>>> field_list = [('field1', CharField()), ('field2', CharField())]
    26672667>>> my_form = MyForm(field_list=field_list)
    26682668>>> print my_form
    2669 <tr><th>Field1:</th><td><input type="text" name="field1" /></td></tr>
    2670 <tr><th>Field2:</th><td><input type="text" name="field2" /></td></tr>
     2669<tr><th>Field1</th><td><input type="text" name="field1" /></td></tr>
     2670<tr><th>Field2</th><td><input type="text" name="field2" /></td></tr>
    26712671>>> field_list = [('field3', CharField()), ('field4', CharField())]
    26722672>>> my_form = MyForm(field_list=field_list)
    26732673>>> print my_form
    2674 <tr><th>Field3:</th><td><input type="text" name="field3" /></td></tr>
    2675 <tr><th>Field4:</th><td><input type="text" name="field4" /></td></tr>
     2674<tr><th>Field3</th><td><input type="text" name="field3" /></td></tr>
     2675<tr><th>Field4</th><td><input type="text" name="field4" /></td></tr>
    26762676
    26772677>>> class MyForm(Form):
    26782678...     default_field_1 = CharField()
     
    26842684>>> field_list = [('field1', CharField()), ('field2', CharField())]
    26852685>>> my_form = MyForm(field_list=field_list)
    26862686>>> print my_form
    2687 <tr><th>Default field 1:</th><td><input type="text" name="default_field_1" /></td></tr>
    2688 <tr><th>Default field 2:</th><td><input type="text" name="default_field_2" /></td></tr>
    2689 <tr><th>Field1:</th><td><input type="text" name="field1" /></td></tr>
    2690 <tr><th>Field2:</th><td><input type="text" name="field2" /></td></tr>
     2687<tr><th>Default field 1</th><td><input type="text" name="default_field_1" /></td></tr>
     2688<tr><th>Default field 2</th><td><input type="text" name="default_field_2" /></td></tr>
     2689<tr><th>Field1</th><td><input type="text" name="field1" /></td></tr>
     2690<tr><th>Field2</th><td><input type="text" name="field2" /></td></tr>
    26912691>>> field_list = [('field3', CharField()), ('field4', CharField())]
    26922692>>> my_form = MyForm(field_list=field_list)
    26932693>>> print my_form
    2694 <tr><th>Default field 1:</th><td><input type="text" name="default_field_1" /></td></tr>
    2695 <tr><th>Default field 2:</th><td><input type="text" name="default_field_2" /></td></tr>
    2696 <tr><th>Field3:</th><td><input type="text" name="field3" /></td></tr>
    2697 <tr><th>Field4:</th><td><input type="text" name="field4" /></td></tr>
     2694<tr><th>Default field 1</th><td><input type="text" name="default_field_1" /></td></tr>
     2695<tr><th>Default field 2</th><td><input type="text" name="default_field_2" /></td></tr>
     2696<tr><th>Field3</th><td><input type="text" name="field3" /></td></tr>
     2697<tr><th>Field4</th><td><input type="text" name="field4" /></td></tr>
    26982698
    26992699Similarly, changes to field attributes do not persist from one Form instance
    27002700to the next.
     
    27522752...     birthday = DateField()
    27532753>>> p = Person(auto_id=False)
    27542754>>> print p
    2755 <tr><th>First name:</th><td><input type="text" name="first_name" /></td></tr>
    2756 <tr><th>Last name:</th><td><input type="text" name="last_name" /></td></tr>
    2757 <tr><th>Birthday:</th><td><input type="text" name="birthday" /><input type="hidden" name="hidden_text" /></td></tr>
     2755<tr><th>First name</th><td><input type="text" name="first_name" /></td></tr>
     2756<tr><th>Last name</th><td><input type="text" name="last_name" /></td></tr>
     2757<tr><th>Birthday</th><td><input type="text" name="birthday" /><input type="hidden" name="hidden_text" /></td></tr>
    27582758>>> print p.as_ul()
    2759 <li>First name: <input type="text" name="first_name" /></li>
    2760 <li>Last name: <input type="text" name="last_name" /></li>
    2761 <li>Birthday: <input type="text" name="birthday" /><input type="hidden" name="hidden_text" /></li>
     2759<li>First name <input type="text" name="first_name" /></li>
     2760<li>Last name <input type="text" name="last_name" /></li>
     2761<li>Birthday <input type="text" name="birthday" /><input type="hidden" name="hidden_text" /></li>
    27622762>>> print p.as_p()
    2763 <p>First name: <input type="text" name="first_name" /></p>
    2764 <p>Last name: <input type="text" name="last_name" /></p>
    2765 <p>Birthday: <input type="text" name="birthday" /><input type="hidden" name="hidden_text" /></p>
     2763<p>First name <input type="text" name="first_name" /></p>
     2764<p>Last name <input type="text" name="last_name" /></p>
     2765<p>Birthday <input type="text" name="birthday" /><input type="hidden" name="hidden_text" /></p>
    27662766
    27672767With auto_id set, a HiddenInput still gets an ID, but it doesn't get a label.
    27682768>>> p = Person(auto_id='id_%s')
    27692769>>> print p
    2770 <tr><th><label for="id_first_name">First name:</label></th><td><input type="text" name="first_name" id="id_first_name" /></td></tr>
    2771 <tr><th><label for="id_last_name">Last name:</label></th><td><input type="text" name="last_name" id="id_last_name" /></td></tr>
    2772 <tr><th><label for="id_birthday">Birthday:</label></th><td><input type="text" name="birthday" id="id_birthday" /><input type="hidden" name="hidden_text" id="id_hidden_text" /></td></tr>
     2770<tr><th><label for="id_first_name">First name</label></th><td><input type="text" name="first_name" id="id_first_name" /></td></tr>
     2771<tr><th><label for="id_last_name">Last name</label></th><td><input type="text" name="last_name" id="id_last_name" /></td></tr>
     2772<tr><th><label for="id_birthday">Birthday</label></th><td><input type="text" name="birthday" id="id_birthday" /><input type="hidden" name="hidden_text" id="id_hidden_text" /></td></tr>
    27732773>>> print p.as_ul()
    2774 <li><label for="id_first_name">First name:</label> <input type="text" name="first_name" id="id_first_name" /></li>
    2775 <li><label for="id_last_name">Last name:</label> <input type="text" name="last_name" id="id_last_name" /></li>
    2776 <li><label for="id_birthday">Birthday:</label> <input type="text" name="birthday" id="id_birthday" /><input type="hidden" name="hidden_text" id="id_hidden_text" /></li>
     2774<li><label for="id_first_name">First name</label> <input type="text" name="first_name" id="id_first_name" /></li>
     2775<li><label for="id_last_name">Last name</label> <input type="text" name="last_name" id="id_last_name" /></li>
     2776<li><label for="id_birthday">Birthday</label> <input type="text" name="birthday" id="id_birthday" /><input type="hidden" name="hidden_text" id="id_hidden_text" /></li>
    27772777>>> print p.as_p()
    2778 <p><label for="id_first_name">First name:</label> <input type="text" name="first_name" id="id_first_name" /></p>
    2779 <p><label for="id_last_name">Last name:</label> <input type="text" name="last_name" id="id_last_name" /></p>
    2780 <p><label for="id_birthday">Birthday:</label> <input type="text" name="birthday" id="id_birthday" /><input type="hidden" name="hidden_text" id="id_hidden_text" /></p>
     2778<p><label for="id_first_name">First name</label> <input type="text" name="first_name" id="id_first_name" /></p>
     2779<p><label for="id_last_name">Last name</label> <input type="text" name="last_name" id="id_last_name" /></p>
     2780<p><label for="id_birthday">Birthday</label> <input type="text" name="birthday" id="id_birthday" /><input type="hidden" name="hidden_text" id="id_hidden_text" /></p>
    27812781
    27822782If a field with a HiddenInput has errors, the as_table() and as_ul() output
    27832783will include the error message(s) with the text "(Hidden field [fieldname]) "
     
    27862786>>> p = Person({'first_name': 'John', 'last_name': 'Lennon', 'birthday': '1940-10-9'}, auto_id=False)
    27872787>>> print p
    27882788<tr><td colspan="2"><ul class="errorlist"><li>(Hidden field hidden_text) This field is required.</li></ul></td></tr>
    2789 <tr><th>First name:</th><td><input type="text" name="first_name" value="John" /></td></tr>
    2790 <tr><th>Last name:</th><td><input type="text" name="last_name" value="Lennon" /></td></tr>
    2791 <tr><th>Birthday:</th><td><input type="text" name="birthday" value="1940-10-9" /><input type="hidden" name="hidden_text" /></td></tr>
     2789<tr><th>First name</th><td><input type="text" name="first_name" value="John" /></td></tr>
     2790<tr><th>Last name</th><td><input type="text" name="last_name" value="Lennon" /></td></tr>
     2791<tr><th>Birthday</th><td><input type="text" name="birthday" value="1940-10-9" /><input type="hidden" name="hidden_text" /></td></tr>
    27922792>>> print p.as_ul()
    27932793<li><ul class="errorlist"><li>(Hidden field hidden_text) This field is required.</li></ul></li>
    2794 <li>First name: <input type="text" name="first_name" value="John" /></li>
    2795 <li>Last name: <input type="text" name="last_name" value="Lennon" /></li>
    2796 <li>Birthday: <input type="text" name="birthday" value="1940-10-9" /><input type="hidden" name="hidden_text" /></li>
     2794<li>First name <input type="text" name="first_name" value="John" /></li>
     2795<li>Last name <input type="text" name="last_name" value="Lennon" /></li>
     2796<li>Birthday <input type="text" name="birthday" value="1940-10-9" /><input type="hidden" name="hidden_text" /></li>
    27972797>>> print p.as_p()
    27982798<ul class="errorlist"><li>(Hidden field hidden_text) This field is required.</li></ul>
    2799 <p>First name: <input type="text" name="first_name" value="John" /></p>
    2800 <p>Last name: <input type="text" name="last_name" value="Lennon" /></p>
    2801 <p>Birthday: <input type="text" name="birthday" value="1940-10-9" /><input type="hidden" name="hidden_text" /></p>
     2799<p>First name <input type="text" name="first_name" value="John" /></p>
     2800<p>Last name <input type="text" name="last_name" value="Lennon" /></p>
     2801<p>Birthday <input type="text" name="birthday" value="1940-10-9" /><input type="hidden" name="hidden_text" /></p>
    28022802
    28032803A corner case: It's possible for a form to have only HiddenInputs.
    28042804>>> class TestForm(Form):
     
    28302830...     field14 = CharField()
    28312831>>> p = TestForm(auto_id=False)
    28322832>>> print p
    2833 <tr><th>Field1:</th><td><input type="text" name="field1" /></td></tr>
    2834 <tr><th>Field2:</th><td><input type="text" name="field2" /></td></tr>
    2835 <tr><th>Field3:</th><td><input type="text" name="field3" /></td></tr>
    2836 <tr><th>Field4:</th><td><input type="text" name="field4" /></td></tr>
    2837 <tr><th>Field5:</th><td><input type="text" name="field5" /></td></tr>
    2838 <tr><th>Field6:</th><td><input type="text" name="field6" /></td></tr>
    2839 <tr><th>Field7:</th><td><input type="text" name="field7" /></td></tr>
    2840 <tr><th>Field8:</th><td><input type="text" name="field8" /></td></tr>
    2841 <tr><th>Field9:</th><td><input type="text" name="field9" /></td></tr>
    2842 <tr><th>Field10:</th><td><input type="text" name="field10" /></td></tr>
    2843 <tr><th>Field11:</th><td><input type="text" name="field11" /></td></tr>
    2844 <tr><th>Field12:</th><td><input type="text" name="field12" /></td></tr>
    2845 <tr><th>Field13:</th><td><input type="text" name="field13" /></td></tr>
    2846 <tr><th>Field14:</th><td><input type="text" name="field14" /></td></tr>
     2833<tr><th>Field1</th><td><input type="text" name="field1" /></td></tr>
     2834<tr><th>Field2</th><td><input type="text" name="field2" /></td></tr>
     2835<tr><th>Field3</th><td><input type="text" name="field3" /></td></tr>
     2836<tr><th>Field4</th><td><input type="text" name="field4" /></td></tr>
     2837<tr><th>Field5</th><td><input type="text" name="field5" /></td></tr>
     2838<tr><th>Field6</th><td><input type="text" name="field6" /></td></tr>
     2839<tr><th>Field7</th><td><input type="text" name="field7" /></td></tr>
     2840<tr><th>Field8</th><td><input type="text" name="field8" /></td></tr>
     2841<tr><th>Field9</th><td><input type="text" name="field9" /></td></tr>
     2842<tr><th>Field10</th><td><input type="text" name="field10" /></td></tr>
     2843<tr><th>Field11</th><td><input type="text" name="field11" /></td></tr>
     2844<tr><th>Field12</th><td><input type="text" name="field12" /></td></tr>
     2845<tr><th>Field13</th><td><input type="text" name="field13" /></td></tr>
     2846<tr><th>Field14</th><td><input type="text" name="field14" /></td></tr>
    28472847
    28482848Some Field classes have an effect on the HTML attributes of their associated
    28492849Widget. If you set max_length in a CharField and its associated widget is
     
    28562856...    address = CharField()                                 # no max_length defined here
    28572857>>> p = UserRegistration(auto_id=False)
    28582858>>> print p.as_ul()
    2859 <li>Username: <input type="text" name="username" maxlength="10" /></li>
    2860 <li>Password: <input type="password" name="password" maxlength="10" /></li>
    2861 <li>Realname: <input type="text" name="realname" maxlength="10" /></li>
    2862 <li>Address: <input type="text" name="address" /></li>
     2859<li>Username <input type="text" name="username" maxlength="10" /></li>
     2860<li>Password <input type="password" name="password" maxlength="10" /></li>
     2861<li>Realname <input type="text" name="realname" maxlength="10" /></li>
     2862<li>Address <input type="text" name="address" /></li>
    28632863
    28642864If you specify a custom "attrs" that includes the "maxlength" attribute,
    28652865the Field's max_length attribute will override whatever "maxlength" you specify
     
    28692869...    password = CharField(max_length=10, widget=PasswordInput)
    28702870>>> p = UserRegistration(auto_id=False)
    28712871>>> print p.as_ul()
    2872 <li>Username: <input type="text" name="username" maxlength="10" /></li>
    2873 <li>Password: <input type="password" name="password" maxlength="10" /></li>
     2872<li>Username <input type="text" name="username" maxlength="10" /></li>
     2873<li>Password <input type="password" name="password" maxlength="10" /></li>
    28742874
    28752875# Specifying labels ###########################################################
    28762876
     
    28832883...    password2 = CharField(widget=PasswordInput, label='Password (again)')
    28842884>>> p = UserRegistration(auto_id=False)
    28852885>>> print p.as_ul()
    2886 <li>Your username: <input type="text" name="username" maxlength="10" /></li>
    2887 <li>Password1: <input type="password" name="password1" /></li>
    2888 <li>Password (again): <input type="password" name="password2" /></li>
     2886<li>Your username <input type="text" name="username" maxlength="10" /></li>
     2887<li>Password1 <input type="password" name="password1" /></li>
     2888<li>Password (again) <input type="password" name="password2" /></li>
    28892889
    2890 Labels for as_* methods will only end in a colon if they don't end in other
     2890Labels for as_* methods will not add a colon to the label, regardless of the last character
    28912891punctuation already.
    28922892>>> class Questions(Form):
    28932893...    q1 = CharField(label='The first question')
     
    28962896...    q4 = CharField(label='Answer this question!')
    28972897...    q5 = CharField(label='The last question. Period.')
    28982898>>> print Questions(auto_id=False).as_p()
    2899 <p>The first question: <input type="text" name="q1" /></p>
     2899<p>The first question <input type="text" name="q1" /></p>
    29002900<p>What is your name? <input type="text" name="q2" /></p>
    29012901<p>The answer to life is: <input type="text" name="q3" /></p>
    29022902<p>Answer this question! <input type="text" name="q4" /></p>
    29032903<p>The last question. Period. <input type="text" name="q5" /></p>
    29042904>>> print Questions().as_p()
    2905 <p><label for="id_q1">The first question:</label> <input type="text" name="q1" id="id_q1" /></p>
     2905<p><label for="id_q1">The first question</label> <input type="text" name="q1" id="id_q1" /></p>
    29062906<p><label for="id_q2">What is your name?</label> <input type="text" name="q2" id="id_q2" /></p>
    29072907<p><label for="id_q3">The answer to life is:</label> <input type="text" name="q3" id="id_q3" /></p>
    29082908<p><label for="id_q4">Answer this question!</label> <input type="text" name="q4" id="id_q4" /></p>
     
    29142914...    password = CharField(widget=PasswordInput, label=u'\u0160\u0110\u0106\u017d\u0107\u017e\u0161\u0111')
    29152915>>> p = UserRegistration(auto_id=False)
    29162916>>> p.as_ul()
    2917 u'<li>\u0160\u0110\u0106\u017d\u0107\u017e\u0161\u0111: <input type="text" name="username" maxlength="10" /></li>\n<li>\u0160\u0110\u0106\u017d\u0107\u017e\u0161\u0111: <input type="password" name="password" /></li>'
     2917u'<li>\u0160\u0110\u0106\u017d\u0107\u017e\u0161\u0111 <input type="text" name="username" maxlength="10" /></li>\n<li>\u0160\u0110\u0106\u017d\u0107\u017e\u0161\u0111 <input type="password" name="password" /></li>'
    29182918
    29192919If a label is set to the empty string for a field, that field won't get a label.
    29202920>>> class UserRegistration(Form):
     
    29232923>>> p = UserRegistration(auto_id=False)
    29242924>>> print p.as_ul()
    29252925<li> <input type="text" name="username" maxlength="10" /></li>
    2926 <li>Password: <input type="password" name="password" /></li>
     2926<li>Password <input type="password" name="password" /></li>
    29272927>>> p = UserRegistration(auto_id='id_%s')
    29282928>>> print p.as_ul()
    29292929<li> <input id="id_username" type="text" name="username" maxlength="10" /></li>
    2930 <li><label for="id_password">Password:</label> <input type="password" name="password" id="id_password" /></li>
     2930<li><label for="id_password">Password</label> <input type="password" name="password" id="id_password" /></li>
    29312931
    29322932If label is None, Django will auto-create the label from the field name. This
    29332933is default behavior.
     
    29362936...    password = CharField(widget=PasswordInput)
    29372937>>> p = UserRegistration(auto_id=False)
    29382938>>> print p.as_ul()
    2939 <li>Username: <input type="text" name="username" maxlength="10" /></li>
    2940 <li>Password: <input type="password" name="password" /></li>
     2939<li>Username <input type="text" name="username" maxlength="10" /></li>
     2940<li>Password <input type="password" name="password" /></li>
    29412941>>> p = UserRegistration(auto_id='id_%s')
    29422942>>> print p.as_ul()
    2943 <li><label for="id_username">Username:</label> <input id="id_username" type="text" name="username" maxlength="10" /></li>
    2944 <li><label for="id_password">Password:</label> <input type="password" name="password" id="id_password" /></li>
     2943<li><label for="id_username">Username</label> <input id="id_username" type="text" name="username" maxlength="10" /></li>
     2944<li><label for="id_password">Password</label> <input type="password" name="password" id="id_password" /></li>
    29452945
    29462946# Initial data ################################################################
    29472947
     
    29572957Here, we're not submitting any data, so the initial value will be displayed.
    29582958>>> p = UserRegistration(auto_id=False)
    29592959>>> print p.as_ul()
    2960 <li>Username: <input type="text" name="username" value="django" maxlength="10" /></li>
    2961 <li>Password: <input type="password" name="password" /></li>
     2960<li>Username <input type="text" name="username" value="django" maxlength="10" /></li>
     2961<li>Password <input type="password" name="password" /></li>
    29622962
    29632963Here, we're submitting data, so the initial value will *not* be displayed.
    29642964>>> p = UserRegistration({}, auto_id=False)
    29652965>>> print p.as_ul()
    2966 <li><ul class="errorlist"><li>This field is required.</li></ul>Username: <input type="text" name="username" maxlength="10" /></li>
    2967 <li><ul class="errorlist"><li>This field is required.</li></ul>Password: <input type="password" name="password" /></li>
     2966<li><ul class="errorlist"><li>This field is required.</li></ul>Username <input type="text" name="username" maxlength="10" /></li>
     2967<li><ul class="errorlist"><li>This field is required.</li></ul>Password <input type="password" name="password" /></li>
    29682968>>> p = UserRegistration({'username': u''}, auto_id=False)
    29692969>>> print p.as_ul()
    2970 <li><ul class="errorlist"><li>This field is required.</li></ul>Username: <input type="text" name="username" maxlength="10" /></li>
    2971 <li><ul class="errorlist"><li>This field is required.</li></ul>Password: <input type="password" name="password" /></li>
     2970<li><ul class="errorlist"><li>This field is required.</li></ul>Username <input type="text" name="username" maxlength="10" /></li>
     2971<li><ul class="errorlist"><li>This field is required.</li></ul>Password <input type="password" name="password" /></li>
    29722972>>> p = UserRegistration({'username': u'foo'}, auto_id=False)
    29732973>>> print p.as_ul()
    2974 <li>Username: <input type="text" name="username" value="foo" maxlength="10" /></li>
    2975 <li><ul class="errorlist"><li>This field is required.</li></ul>Password: <input type="password" name="password" /></li>
     2974<li>Username <input type="text" name="username" value="foo" maxlength="10" /></li>
     2975<li><ul class="errorlist"><li>This field is required.</li></ul>Password <input type="password" name="password" /></li>
    29762976
    29772977An 'initial' value is *not* used as a fallback if data is not provided. In this
    29782978example, we don't provide a value for 'username', and the form raises a
     
    29982998Here, we're not submitting any data, so the initial value will be displayed.
    29992999>>> p = UserRegistration(initial={'username': 'django'}, auto_id=False)
    30003000>>> print p.as_ul()
    3001 <li>Username: <input type="text" name="username" value="django" maxlength="10" /></li>
    3002 <li>Password: <input type="password" name="password" /></li>
     3001<li>Username <input type="text" name="username" value="django" maxlength="10" /></li>
     3002<li>Password <input type="password" name="password" /></li>
    30033003>>> p = UserRegistration(initial={'username': 'stephane'}, auto_id=False)
    30043004>>> print p.as_ul()
    3005 <li>Username: <input type="text" name="username" value="stephane" maxlength="10" /></li>
    3006 <li>Password: <input type="password" name="password" /></li>
     3005<li>Username <input type="text" name="username" value="stephane" maxlength="10" /></li>
     3006<li>Password <input type="password" name="password" /></li>
    30073007
    30083008The 'initial' parameter is meaningless if you pass data.
    30093009>>> p = UserRegistration({}, initial={'username': 'django'}, auto_id=False)
    30103010>>> print p.as_ul()
    3011 <li><ul class="errorlist"><li>This field is required.</li></ul>Username: <input type="text" name="username" maxlength="10" /></li>
    3012 <li><ul class="errorlist"><li>This field is required.</li></ul>Password: <input type="password" name="password" /></li>
     3011<li><ul class="errorlist"><li>This field is required.</li></ul>Username <input type="text" name="username" maxlength="10" /></li>
     3012<li><ul class="errorlist"><li>This field is required.</li></ul>Password <input type="password" name="password" /></li>
    30133013>>> p = UserRegistration({'username': u''}, initial={'username': 'django'}, auto_id=False)
    30143014>>> print p.as_ul()
    3015 <li><ul class="errorlist"><li>This field is required.</li></ul>Username: <input type="text" name="username" maxlength="10" /></li>
    3016 <li><ul class="errorlist"><li>This field is required.</li></ul>Password: <input type="password" name="password" /></li>
     3015<li><ul class="errorlist"><li>This field is required.</li></ul>Username <input type="text" name="username" maxlength="10" /></li>
     3016<li><ul class="errorlist"><li>This field is required.</li></ul>Password <input type="password" name="password" /></li>
    30173017>>> p = UserRegistration({'username': u'foo'}, initial={'username': 'django'}, auto_id=False)
    30183018>>> print p.as_ul()
    3019 <li>Username: <input type="text" name="username" value="foo" maxlength="10" /></li>
    3020 <li><ul class="errorlist"><li>This field is required.</li></ul>Password: <input type="password" name="password" /></li>
     3019<li>Username <input type="text" name="username" value="foo" maxlength="10" /></li>
     3020<li><ul class="errorlist"><li>This field is required.</li></ul>Password <input type="password" name="password" /></li>
    30213021
    30223022A dynamic 'initial' value is *not* used as a fallback if data is not provided.
    30233023In this example, we don't provide a value for 'username', and the form raises a
     
    30353035...    password = CharField(widget=PasswordInput)
    30363036>>> p = UserRegistration(initial={'username': 'babik'}, auto_id=False)
    30373037>>> print p.as_ul()
    3038 <li>Username: <input type="text" name="username" value="babik" maxlength="10" /></li>
    3039 <li>Password: <input type="password" name="password" /></li>
     3038<li>Username <input type="text" name="username" value="babik" maxlength="10" /></li>
     3039<li>Password <input type="password" name="password" /></li>
    30403040
    30413041# Callable initial data ########################################################
    30423042
     
    30563056Here, we're not submitting any data, so the initial value will be displayed.
    30573057>>> p = UserRegistration(initial={'username': initial_django}, auto_id=False)
    30583058>>> print p.as_ul()
    3059 <li>Username: <input type="text" name="username" value="django" maxlength="10" /></li>
    3060 <li>Password: <input type="password" name="password" /></li>
     3059<li>Username <input type="text" name="username" value="django" maxlength="10" /></li>
     3060<li>Password <input type="password" name="password" /></li>
    30613061
    30623062The 'initial' parameter is meaningless if you pass data.
    30633063>>> p = UserRegistration({}, initial={'username': initial_django}, auto_id=False)
    30643064>>> print p.as_ul()
    3065 <li><ul class="errorlist"><li>This field is required.</li></ul>Username: <input type="text" name="username" maxlength="10" /></li>
    3066 <li><ul class="errorlist"><li>This field is required.</li></ul>Password: <input type="password" name="password" /></li>
     3065<li><ul class="errorlist"><li>This field is required.</li></ul>Username <input type="text" name="username" maxlength="10" /></li>
     3066<li><ul class="errorlist"><li>This field is required.</li></ul>Password <input type="password" name="password" /></li>
    30673067>>> p = UserRegistration({'username': u''}, initial={'username': initial_django}, auto_id=False)
    30683068>>> print p.as_ul()
    3069 <li><ul class="errorlist"><li>This field is required.</li></ul>Username: <input type="text" name="username" maxlength="10" /></li>
    3070 <li><ul class="errorlist"><li>This field is required.</li></ul>Password: <input type="password" name="password" /></li>
     3069<li><ul class="errorlist"><li>This field is required.</li></ul>Username <input type="text" name="username" maxlength="10" /></li>
     3070<li><ul class="errorlist"><li>This field is required.</li></ul>Password <input type="password" name="password" /></li>
    30713071>>> p = UserRegistration({'username': u'foo'}, initial={'username': initial_django}, auto_id=False)
    30723072>>> print p.as_ul()
    3073 <li>Username: <input type="text" name="username" value="foo" maxlength="10" /></li>
    3074 <li><ul class="errorlist"><li>This field is required.</li></ul>Password: <input type="password" name="password" /></li>
     3073<li>Username <input type="text" name="username" value="foo" maxlength="10" /></li>
     3074<li><ul class="errorlist"><li>This field is required.</li></ul>Password <input type="password" name="password" /></li>
    30753075
    30763076A callable 'initial' value is *not* used as a fallback if data is not provided.
    30773077In this example, we don't provide a value for 'username', and the form raises a
     
    30893089...    password = CharField(widget=PasswordInput)
    30903090>>> p = UserRegistration(auto_id=False)
    30913091>>> print p.as_ul()
    3092 <li>Username: <input type="text" name="username" value="django" maxlength="10" /></li>
    3093 <li>Password: <input type="password" name="password" /></li>
     3092<li>Username <input type="text" name="username" value="django" maxlength="10" /></li>
     3093<li>Password <input type="password" name="password" /></li>
    30943094>>> p = UserRegistration(initial={'username': initial_stephane}, auto_id=False)
    30953095>>> print p.as_ul()
    3096 <li>Username: <input type="text" name="username" value="stephane" maxlength="10" /></li>
    3097 <li>Password: <input type="password" name="password" /></li>
     3096<li>Username <input type="text" name="username" value="stephane" maxlength="10" /></li>
     3097<li>Password <input type="password" name="password" /></li>
    30983098
    30993099# Help text ###################################################################
    31003100
     
    31053105...    password = CharField(widget=PasswordInput, help_text='Choose wisely.')
    31063106>>> p = UserRegistration(auto_id=False)
    31073107>>> print p.as_ul()
    3108 <li>Username: <input type="text" name="username" maxlength="10" /> e.g., user@example.com</li>
    3109 <li>Password: <input type="password" name="password" /> Choose wisely.</li>
     3108<li>Username <input type="text" name="username" maxlength="10" /> e.g., user@example.com</li>
     3109<li>Password <input type="password" name="password" /> Choose wisely.</li>
    31103110>>> print p.as_p()
    3111 <p>Username: <input type="text" name="username" maxlength="10" /> e.g., user@example.com</p>
    3112 <p>Password: <input type="password" name="password" /> Choose wisely.</p>
     3111<p>Username <input type="text" name="username" maxlength="10" /> e.g., user@example.com</p>
     3112<p>Password <input type="password" name="password" /> Choose wisely.</p>
    31133113>>> print p.as_table()
    3114 <tr><th>Username:</th><td><input type="text" name="username" maxlength="10" /><br />e.g., user@example.com</td></tr>
    3115 <tr><th>Password:</th><td><input type="password" name="password" /><br />Choose wisely.</td></tr>
     3114<tr><th>Username</th><td><input type="text" name="username" maxlength="10" /><br />e.g., user@example.com</td></tr>
     3115<tr><th>Password</th><td><input type="password" name="password" /><br />Choose wisely.</td></tr>
    31163116
    31173117The help text is displayed whether or not data is provided for the form.
    31183118>>> p = UserRegistration({'username': u'foo'}, auto_id=False)
    31193119>>> print p.as_ul()
    3120 <li>Username: <input type="text" name="username" value="foo" maxlength="10" /> e.g., user@example.com</li>
    3121 <li><ul class="errorlist"><li>This field is required.</li></ul>Password: <input type="password" name="password" /> Choose wisely.</li>
     3120<li>Username <input type="text" name="username" value="foo" maxlength="10" /> e.g., user@example.com</li>
     3121<li><ul class="errorlist"><li>This field is required.</li></ul>Password <input type="password" name="password" /> Choose wisely.</li>
    31223122
    31233123help_text is not displayed for hidden fields. It can be used for documentation
    31243124purposes, though.
     
    31283128...    next = CharField(widget=HiddenInput, initial='/', help_text='Redirect destination')
    31293129>>> p = UserRegistration(auto_id=False)
    31303130>>> print p.as_ul()
    3131 <li>Username: <input type="text" name="username" maxlength="10" /> e.g., user@example.com</li>
    3132 <li>Password: <input type="password" name="password" /><input type="hidden" name="next" value="/" /></li>
     3131<li>Username <input type="text" name="username" maxlength="10" /> e.g., user@example.com</li>
     3132<li>Password <input type="password" name="password" /><input type="hidden" name="next" value="/" /></li>
    31333133
    31343134Help text can include arbitrary Unicode characters.
    31353135>>> class UserRegistration(Form):
    31363136...    username = CharField(max_length=10, help_text='ŠĐĆŽćžšđ')
    31373137>>> p = UserRegistration(auto_id=False)
    31383138>>> p.as_ul()
    3139 u'<li>Username: <input type="text" name="username" maxlength="10" /> \u0160\u0110\u0106\u017d\u0107\u017e\u0161\u0111</li>'
     3139u'<li>Username <input type="text" name="username" maxlength="10" /> \u0160\u0110\u0106\u017d\u0107\u017e\u0161\u0111</li>'
    31403140
    31413141# Subclassing forms ###########################################################
    31423142
     
    31513151...     instrument = CharField()
    31523152>>> p = Person(auto_id=False)
    31533153>>> print p.as_ul()
    3154 <li>First name: <input type="text" name="first_name" /></li>
    3155 <li>Last name: <input type="text" name="last_name" /></li>
    3156 <li>Birthday: <input type="text" name="birthday" /></li>
     3154<li>First name <input type="text" name="first_name" /></li>
     3155<li>Last name <input type="text" name="last_name" /></li>
     3156<li>Birthday <input type="text" name="birthday" /></li>
    31573157>>> m = Musician(auto_id=False)
    31583158>>> print m.as_ul()
    3159 <li>First name: <input type="text" name="first_name" /></li>
    3160 <li>Last name: <input type="text" name="last_name" /></li>
    3161 <li>Birthday: <input type="text" name="birthday" /></li>
    3162 <li>Instrument: <input type="text" name="instrument" /></li>
     3159<li>First name <input type="text" name="first_name" /></li>
     3160<li>Last name <input type="text" name="last_name" /></li>
     3161<li>Birthday <input type="text" name="birthday" /></li>
     3162<li>Instrument <input type="text" name="instrument" /></li>
    31633163
    31643164Yes, you can subclass multiple forms. The fields are added in the order in
    31653165which the parent classes are listed.
     
    31733173...     haircut_type = CharField()
    31743174>>> b = Beatle(auto_id=False)
    31753175>>> print b.as_ul()
    3176 <li>First name: <input type="text" name="first_name" /></li>
    3177 <li>Last name: <input type="text" name="last_name" /></li>
    3178 <li>Birthday: <input type="text" name="birthday" /></li>
    3179 <li>Instrument: <input type="text" name="instrument" /></li>
    3180 <li>Haircut type: <input type="text" name="haircut_type" /></li>
     3176<li>First name <input type="text" name="first_name" /></li>
     3177<li>Last name <input type="text" name="last_name" /></li>
     3178<li>Birthday <input type="text" name="birthday" /></li>
     3179<li>Instrument <input type="text" name="instrument" /></li>
     3180<li>Haircut type <input type="text" name="haircut_type" /></li>
    31813181
    31823182# Forms with prefixes #########################################################
    31833183
     
    31993199... }
    32003200>>> p = Person(data, prefix='person1')
    32013201>>> print p.as_ul()
    3202 <li><label for="id_person1-first_name">First name:</label> <input type="text" name="person1-first_name" value="John" id="id_person1-first_name" /></li>
    3203 <li><label for="id_person1-last_name">Last name:</label> <input type="text" name="person1-last_name" value="Lennon" id="id_person1-last_name" /></li>
    3204 <li><label for="id_person1-birthday">Birthday:</label> <input type="text" name="person1-birthday" value="1940-10-9" id="id_person1-birthday" /></li>
     3202<li><label for="id_person1-first_name">First name</label> <input type="text" name="person1-first_name" value="John" id="id_person1-first_name" /></li>
     3203<li><label for="id_person1-last_name">Last name</label> <input type="text" name="person1-last_name" value="Lennon" id="id_person1-last_name" /></li>
     3204<li><label for="id_person1-birthday">Birthday</label> <input type="text" name="person1-birthday" value="1940-10-9" id="id_person1-birthday" /></li>
    32053205>>> print p['first_name']
    32063206<input type="text" name="person1-first_name" value="John" id="id_person1-first_name" />
    32073207>>> print p['last_name']
     
    32763276...         return self.prefix and '%s-prefix-%s' % (self.prefix, field_name) or field_name
    32773277>>> p = Person(prefix='foo')
    32783278>>> print p.as_ul()
    3279 <li><label for="id_foo-prefix-first_name">First name:</label> <input type="text" name="foo-prefix-first_name" id="id_foo-prefix-first_name" /></li>
    3280 <li><label for="id_foo-prefix-last_name">Last name:</label> <input type="text" name="foo-prefix-last_name" id="id_foo-prefix-last_name" /></li>
    3281 <li><label for="id_foo-prefix-birthday">Birthday:</label> <input type="text" name="foo-prefix-birthday" id="id_foo-prefix-birthday" /></li>
     3279<li><label for="id_foo-prefix-first_name">First name</label> <input type="text" name="foo-prefix-first_name" id="id_foo-prefix-first_name" /></li>
     3280<li><label for="id_foo-prefix-last_name">Last name</label> <input type="text" name="foo-prefix-last_name" id="id_foo-prefix-last_name" /></li>
     3281<li><label for="id_foo-prefix-birthday">Birthday</label> <input type="text" name="foo-prefix-birthday" id="id_foo-prefix-birthday" /></li>
    32823282>>> data = {
    32833283...     'foo-prefix-first_name': u'John',
    32843284...     'foo-prefix-last_name': u'Lennon',
     
    33503350...     file1 = FileField()
    33513351>>> f = FileForm(auto_id=False)
    33523352>>> print f
    3353 <tr><th>File1:</th><td><input type="file" name="file1" /></td></tr>
     3353<tr><th>File1</th><td><input type="file" name="file1" /></td></tr>
    33543354
    33553355>>> f = FileForm(data={}, files={}, auto_id=False)
    33563356>>> print f
    3357 <tr><th>File1:</th><td><ul class="errorlist"><li>This field is required.</li></ul><input type="file" name="file1" /></td></tr>
     3357<tr><th>File1</th><td><ul class="errorlist"><li>This field is required.</li></ul><input type="file" name="file1" /></td></tr>
    33583358
    33593359>>> f = FileForm(data={}, files={'file1': {'filename': 'name', 'content':''}}, auto_id=False)
    33603360>>> print f
    3361 <tr><th>File1:</th><td><ul class="errorlist"><li>The submitted file is empty.</li></ul><input type="file" name="file1" /></td></tr>
     3361<tr><th>File1</th><td><ul class="errorlist"><li>The submitted file is empty.</li></ul><input type="file" name="file1" /></td></tr>
    33623362
    33633363>>> f = FileForm(data={}, files={'file1': 'something that is not a file'}, auto_id=False)
    33643364>>> print f
    3365 <tr><th>File1:</th><td><ul class="errorlist"><li>No file was submitted. Check the encoding type on the form.</li></ul><input type="file" name="file1" /></td></tr>
     3365<tr><th>File1</th><td><ul class="errorlist"><li>No file was submitted. Check the encoding type on the form.</li></ul><input type="file" name="file1" /></td></tr>
    33663366
    33673367>>> f = FileForm(data={}, files={'file1': {'filename': 'name', 'content':'some content'}}, auto_id=False)
    33683368>>> print f
    3369 <tr><th>File1:</th><td><input type="file" name="file1" /></td></tr>
     3369<tr><th>File1</th><td><input type="file" name="file1" /></td></tr>
    33703370>>> f.is_valid()
    33713371True
    33723372
     
    33953395>>> print my_function('GET', {})
    33963396<form action="" method="post">
    33973397<table>
    3398 <tr><th>Username:</th><td><input type="text" name="username" maxlength="10" /></td></tr>
    3399 <tr><th>Password1:</th><td><input type="password" name="password1" /></td></tr>
    3400 <tr><th>Password2:</th><td><input type="password" name="password2" /></td></tr>
     3398<tr><th>Username</th><td><input type="text" name="username" maxlength="10" /></td></tr>
     3399<tr><th>Password1</th><td><input type="password" name="password1" /></td></tr>
     3400<tr><th>Password2</th><td><input type="password" name="password2" /></td></tr>
    34013401</table>
    34023402<input type="submit" />
    34033403</form>
     
    34073407<form action="" method="post">
    34083408<table>
    34093409<tr><td colspan="2"><ul class="errorlist"><li>Please make sure your passwords match.</li></ul></td></tr>
    3410 <tr><th>Username:</th><td><ul class="errorlist"><li>Ensure this value has at most 10 characters (it has 23).</li></ul><input type="text" name="username" value="this-is-a-long-username" maxlength="10" /></td></tr>
    3411 <tr><th>Password1:</th><td><input type="password" name="password1" value="foo" /></td></tr>
    3412 <tr><th>Password2:</th><td><input type="password" name="password2" value="bar" /></td></tr>
     3410<tr><th>Username</th><td><ul class="errorlist"><li>Ensure this value has at most 10 characters (it has 23).</li></ul><input type="text" name="username" value="this-is-a-long-username" maxlength="10" /></td></tr>
     3411<tr><th>Password1</th><td><input type="password" name="password1" value="foo" /></td></tr>
     3412<tr><th>Password2</th><td><input type="password" name="password2" value="bar" /></td></tr>
    34133413</table>
    34143414<input type="submit" />
    34153415</form>
     
    34353435displaying all the errors, including any that might not be associated with a
    34363436particular field.
    34373437>>> t = Template('''<form action="">
    3438 ... {{ form.username.errors.as_ul }}<p><label>Your username: {{ form.username }}</label></p>
    3439 ... {{ form.password1.errors.as_ul }}<p><label>Password: {{ form.password1 }}</label></p>
    3440 ... {{ form.password2.errors.as_ul }}<p><label>Password (again): {{ form.password2 }}</label></p>
     3438... {{ form.username.errors.as_ul }}<p><label>Your username {{ form.username }}</label></p>
     3439... {{ form.password1.errors.as_ul }}<p><label>Password {{ form.password1 }}</label></p>
     3440... {{ form.password2.errors.as_ul }}<p><label>Password (again) {{ form.password2 }}</label></p>
    34413441... <input type="submit" />
    34423442... </form>''')
    34433443>>> print t.render(Context({'form': UserRegistration(auto_id=False)}))
    34443444<form action="">
    3445 <p><label>Your username: <input type="text" name="username" maxlength="10" /></label></p>
    3446 <p><label>Password: <input type="password" name="password1" /></label></p>
    3447 <p><label>Password (again): <input type="password" name="password2" /></label></p>
     3445<p><label>Your username <input type="text" name="username" maxlength="10" /></label></p>
     3446<p><label>Password <input type="password" name="password1" /></label></p>
     3447<p><label>Password (again) <input type="password" name="password2" /></label></p>
    34483448<input type="submit" />
    34493449</form>
    34503450>>> print t.render(Context({'form': UserRegistration({'username': 'django'}, auto_id=False)}))
    34513451<form action="">
    3452 <p><label>Your username: <input type="text" name="username" value="django" maxlength="10" /></label></p>
    3453 <ul class="errorlist"><li>This field is required.</li></ul><p><label>Password: <input type="password" name="password1" /></label></p>
    3454 <ul class="errorlist"><li>This field is required.</li></ul><p><label>Password (again): <input type="password" name="password2" /></label></p>
     3452<p><label>Your username <input type="text" name="username" value="django" maxlength="10" /></label></p>
     3453<ul class="errorlist"><li>This field is required.</li></ul><p><label>Password <input type="password" name="password1" /></label></p>
     3454<ul class="errorlist"><li>This field is required.</li></ul><p><label>Password (again) <input type="password" name="password2" /></label></p>
    34553455<input type="submit" />
    34563456</form>
    34573457
     
    34603460'label', Django will use the field name with underscores converted to spaces,
    34613461and the initial letter capitalized.
    34623462>>> t = Template('''<form action="">
    3463 ... <p><label>{{ form.username.label }}: {{ form.username }}</label></p>
    3464 ... <p><label>{{ form.password1.label }}: {{ form.password1 }}</label></p>
    3465 ... <p><label>{{ form.password2.label }}: {{ form.password2 }}</label></p>
     3463... <p><label>{{ form.username.label }} {{ form.username }}</label></p>
     3464... <p><label>{{ form.password1.label }} {{ form.password1 }}</label></p>
     3465... <p><label>{{ form.password2.label }} {{ form.password2 }}</label></p>
    34663466... <input type="submit" />
    34673467... </form>''')
    34683468>>> print t.render(Context({'form': UserRegistration(auto_id=False)}))
    34693469<form action="">
    3470 <p><label>Username: <input type="text" name="username" maxlength="10" /></label></p>
    3471 <p><label>Password1: <input type="password" name="password1" /></label></p>
    3472 <p><label>Password2: <input type="password" name="password2" /></label></p>
     3470<p><label>Username <input type="text" name="username" maxlength="10" /></label></p>
     3471<p><label>Password1 <input type="password" name="password1" /></label></p>
     3472<p><label>Password2 <input type="password" name="password2" /></label></p>
    34733473<input type="submit" />
    34743474</form>
    34753475
     
    34783478Recall from above that passing the "auto_id" argument to a Form gives each
    34793479field an "id" attribute.
    34803480>>> t = Template('''<form action="">
    3481 ... <p>{{ form.username.label_tag }}: {{ form.username }}</p>
    3482 ... <p>{{ form.password1.label_tag }}: {{ form.password1 }}</p>
    3483 ... <p>{{ form.password2.label_tag }}: {{ form.password2 }}</p>
     3481... <p>{{ form.username.label_tag }} {{ form.username }}</p>
     3482... <p>{{ form.password1.label_tag }} {{ form.password1 }}</p>
     3483... <p>{{ form.password2.label_tag }} {{ form.password2 }}</p>
    34843484... <input type="submit" />
    34853485... </form>''')
    34863486>>> print t.render(Context({'form': UserRegistration(auto_id=False)}))
    34873487<form action="">
    3488 <p>Username: <input type="text" name="username" maxlength="10" /></p>
    3489 <p>Password1: <input type="password" name="password1" /></p>
    3490 <p>Password2: <input type="password" name="password2" /></p>
     3488<p>Username <input type="text" name="username" maxlength="10" /></p>
     3489<p>Password1 <input type="password" name="password1" /></p>
     3490<p>Password2 <input type="password" name="password2" /></p>
    34913491<input type="submit" />
    34923492</form>
    34933493>>> print t.render(Context({'form': UserRegistration(auto_id='id_%s')}))
    34943494<form action="">
    3495 <p><label for="id_username">Username</label>: <input id="id_username" type="text" name="username" maxlength="10" /></p>
    3496 <p><label for="id_password1">Password1</label>: <input type="password" name="password1" id="id_password1" /></p>
    3497 <p><label for="id_password2">Password2</label>: <input type="password" name="password2" id="id_password2" /></p>
     3495<p><label for="id_username">Username</label> <input id="id_username" type="text" name="username" maxlength="10" /></p>
     3496<p><label for="id_password1">Password1</label> <input type="password" name="password1" id="id_password1" /></p>
     3497<p><label for="id_password2">Password2</label> <input type="password" name="password2" id="id_password2" /></p>
    34983498<input type="submit" />
    34993499</form>
    35003500
    35013501User form.[field].help_text to output a field's help text. If the given field
    35023502does not have help text, nothing will be output.
    35033503>>> t = Template('''<form action="">
    3504 ... <p>{{ form.username.label_tag }}: {{ form.username }}<br />{{ form.username.help_text }}</p>
    3505 ... <p>{{ form.password1.label_tag }}: {{ form.password1 }}</p>
    3506 ... <p>{{ form.password2.label_tag }}: {{ form.password2 }}</p>
     3504... <p>{{ form.username.label_tag }} {{ form.username }}<br />{{ form.username.help_text }}</p>
     3505... <p>{{ form.password1.label_tag }} {{ form.password1 }}</p>
     3506... <p>{{ form.password2.label_tag }} {{ form.password2 }}</p>
    35073507... <input type="submit" />
    35083508... </form>''')
    35093509>>> print t.render(Context({'form': UserRegistration(auto_id=False)}))
    35103510<form action="">
    3511 <p>Username: <input type="text" name="username" maxlength="10" /><br />Good luck picking a username that doesn't already exist.</p>
    3512 <p>Password1: <input type="password" name="password1" /></p>
    3513 <p>Password2: <input type="password" name="password2" /></p>
     3511<p>Username <input type="text" name="username" maxlength="10" /><br />Good luck picking a username that doesn't already exist.</p>
     3512<p>Password1 <input type="password" name="password1" /></p>
     3513<p>Password2 <input type="password" name="password2" /></p>
    35143514<input type="submit" />
    35153515</form>
    35163516>>> Template('{{ form.password1.help_text }}').render(Context({'form': UserRegistration(auto_id=False)}))
     
    35303530template. If used on its own, it is displayed as a <ul> (or an empty string, if
    35313531the list of errors is empty). You can also use it in {% if %} statements.
    35323532>>> t = Template('''<form action="">
    3533 ... {{ form.username.errors.as_ul }}<p><label>Your username: {{ form.username }}</label></p>
    3534 ... {{ form.password1.errors.as_ul }}<p><label>Password: {{ form.password1 }}</label></p>
    3535 ... {{ form.password2.errors.as_ul }}<p><label>Password (again): {{ form.password2 }}</label></p>
     3533... {{ form.username.errors.as_ul }}<p><label>Your username {{ form.username }}</label></p>
     3534... {{ form.password1.errors.as_ul }}<p><label>Password {{ form.password1 }}</label></p>
     3535... {{ form.password2.errors.as_ul }}<p><label>Password (again) {{ form.password2 }}</label></p>
    35363536... <input type="submit" />
    35373537... </form>''')
    35383538>>> print t.render(Context({'form': UserRegistration({'username': 'django', 'password1': 'foo', 'password2': 'bar'}, auto_id=False)}))
    35393539<form action="">
    3540 <p><label>Your username: <input type="text" name="username" value="django" maxlength="10" /></label></p>
    3541 <p><label>Password: <input type="password" name="password1" value="foo" /></label></p>
    3542 <p><label>Password (again): <input type="password" name="password2" value="bar" /></label></p>
     3540<p><label>Your username <input type="text" name="username" value="django" maxlength="10" /></label></p>
     3541<p><label>Password <input type="password" name="password1" value="foo" /></label></p>
     3542<p><label>Password (again) <input type="password" name="password2" value="bar" /></label></p>
    35433543<input type="submit" />
    35443544</form>
    35453545>>> t = Template('''<form action="">
    35463546... {{ form.non_field_errors }}
    3547 ... {{ form.username.errors.as_ul }}<p><label>Your username: {{ form.username }}</label></p>
    3548 ... {{ form.password1.errors.as_ul }}<p><label>Password: {{ form.password1 }}</label></p>
    3549 ... {{ form.password2.errors.as_ul }}<p><label>Password (again): {{ form.password2 }}</label></p>
     3547... {{ form.username.errors.as_ul }}<p><label>Your username {{ form.username }}</label></p>
     3548... {{ form.password1.errors.as_ul }}<p><label>Password {{ form.password1 }}</label></p>
     3549... {{ form.password2.errors.as_ul }}<p><label>Password (again) {{ form.password2 }}</label></p>
    35503550... <input type="submit" />
    35513551... </form>''')
    35523552>>> print t.render(Context({'form': UserRegistration({'username': 'django', 'password1': 'foo', 'password2': 'bar'}, auto_id=False)}))
    35533553<form action="">
    35543554<ul class="errorlist"><li>Please make sure your passwords match.</li></ul>
    3555 <p><label>Your username: <input type="text" name="username" value="django" maxlength="10" /></label></p>
    3556 <p><label>Password: <input type="password" name="password1" value="foo" /></label></p>
    3557 <p><label>Password (again): <input type="password" name="password2" value="bar" /></label></p>
     3555<p><label>Your username <input type="text" name="username" value="django" maxlength="10" /></label></p>
     3556<p><label>Password <input type="password" name="password1" value="foo" /></label></p>
     3557<p><label>Password (again) <input type="password" name="password2" value="bar" /></label></p>
    35583558<input type="submit" />
    35593559</form>
    35603560
     
    37803780...     field1 = ComplexField(widget=w)
    37813781>>> f = ComplexFieldForm()
    37823782>>> print f
    3783 <tr><th><label for="id_field1_0">Field1:</label></th><td><input type="text" name="field1_0" id="id_field1_0" />
     3783<tr><th><label for="id_field1_0">Field1</label></th><td><input type="text" name="field1_0" id="id_field1_0" />
    37843784<select multiple="multiple" name="field1_1" id="id_field1_1">
    37853785<option value="J">John</option>
    37863786<option value="P">Paul</option>
     
    37913791
    37923792>>> f = ComplexFieldForm({'field1_0':'some text','field1_1':['J','P'], 'field1_2_0':'2007-04-25', 'field1_2_1':'06:24:00'})
    37933793>>> print f
    3794 <tr><th><label for="id_field1_0">Field1:</label></th><td><input type="text" name="field1_0" value="some text" id="id_field1_0" />
     3794<tr><th><label for="id_field1_0">Field1</label></th><td><input type="text" name="field1_0" value="some text" id="id_field1_0" />
    37953795<select multiple="multiple" name="field1_1" id="id_field1_1">
    37963796<option value="J" selected="selected">John</option>
    37973797<option value="P" selected="selected">Paul</option>
     
    38643864>>> data = dict(email='invalid')
    38653865>>> f = CommentForm(data, auto_id=False, error_class=DivErrorList)
    38663866>>> print f.as_p()
    3867 <p>Name: <input type="text" name="name" maxlength="50" /></p>
     3867<p>Name <input type="text" name="name" maxlength="50" /></p>
    38683868<div class="errorlist"><div class="error">Enter a valid e-mail address.</div></div>
    3869 <p>Email: <input type="text" name="email" value="invalid" /></p>
     3869<p>Email <input type="text" name="email" value="invalid" /></p>
    38703870<div class="errorlist"><div class="error">This field is required.</div></div>
    3871 <p>Comment: <input type="text" name="comment" /></p>
     3871<p>Comment <input type="text" name="comment" /></p>
    38723872
    38733873#################################
    38743874# Test multipart-encoded form #
  • tests/regressiontests/forms/regressions.py

     
    99...     f1 = CharField(max_length=10, widget=TextInput(attrs=extra_attrs))
    1010...     f2 = CharField(widget=TextInput(attrs=extra_attrs))
    1111>>> TestForm(auto_id=False).as_p()
    12 u'<p>F1: <input type="text" class="special" name="f1" maxlength="10" /></p>\n<p>F2: <input type="text" class="special" name="f2" /></p>'
     12u'<p>F1 <input type="text" class="special" name="f1" maxlength="10" /></p>\n<p>F2 <input type="text" class="special" name="f2" /></p>'
    1313
    1414#######################
    1515# Tests for form i18n #
     
    2121...     username = CharField(max_length=10, label=ugettext_lazy('Username'))
    2222>>> f = SomeForm()
    2323>>> print f.as_p()
    24 <p><label for="id_username">Username:</label> <input id="id_username" type="text" name="username" maxlength="10" /></p>
     24<p><label for="id_username">Username</label> <input id="id_username" type="text" name="username" maxlength="10" /></p>
    2525
    2626Translations are done at rendering time, so multi-lingual apps can define forms
    2727early and still send back the right translation.
     
    2929# XFAIL
    3030>>> activate('de')
    3131>>> print f.as_p()
    32 <p><label for="id_username">Benutzername:</label> <input id="id_username" type="text" name="username" maxlength="10" /></p>
     32<p><label for="id_username">Benutzername</label> <input id="id_username" type="text" name="username" maxlength="10" /></p>
    3333>>> activate('pl')
    3434>>> f.as_p()
    35 u'<p><label for="id_username">Nazwa u\u017cytkownika:</label> <input id="id_username" type="text" name="username" maxlength="10" /></p>'
     35u'<p><label for="id_username">Nazwa u\u017cytkownika</label> <input id="id_username" type="text" name="username" maxlength="10" /></p>'
    3636>>> deactivate()
    3737
    3838Unicode decoding problems...
     
    4141...     somechoice = ChoiceField(choices=GENDERS, widget=RadioSelect(), label=u'\xc5\xf8\xdf')
    4242>>> f = SomeForm()
    4343>>> f.as_p()
    44 u'<p><label for="id_somechoice_0">\xc5\xf8\xdf:</label> <ul>\n<li><label><input type="radio" id="id_somechoice_0" value="\xc5" name="somechoice" /> En tied\xe4</label></li>\n<li><label><input type="radio" id="id_somechoice_1" value="\xf8" name="somechoice" /> Mies</label></li>\n<li><label><input type="radio" id="id_somechoice_2" value="\xdf" name="somechoice" /> Nainen</label></li>\n</ul></p>'
     44u'<p><label for="id_somechoice_0">\xc5\xf8\xdf</label> <ul>\n<li><label><input type="radio" id="id_somechoice_0" value="\xc5" name="somechoice" /> En tied\xe4</label></li>\n<li><label><input type="radio" id="id_somechoice_1" value="\xf8" name="somechoice" /> Mies</label></li>\n<li><label><input type="radio" id="id_somechoice_2" value="\xdf" name="somechoice" /> Nainen</label></li>\n</ul></p>'
    4545
    4646Testing choice validation with UTF-8 bytestrings as input (these are the
    4747Russian abbreviations "мес." and "шт.".
     
    5757>>> activate('ru')
    5858>>> f = SomeForm({})
    5959>>> f.as_p()
    60 u'<ul class="errorlist"><li>\u041e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0435 \u043f\u043e\u043b\u0435.</li></ul>\n<p><label for="id_somechoice_0">\xc5\xf8\xdf:</label> <ul>\n<li><label><input type="radio" id="id_somechoice_0" value="\xc5" name="somechoice" /> En tied\xe4</label></li>\n<li><label><input type="radio" id="id_somechoice_1" value="\xf8" name="somechoice" /> Mies</label></li>\n<li><label><input type="radio" id="id_somechoice_2" value="\xdf" name="somechoice" /> Nainen</label></li>\n</ul></p>'
     60u'<ul class="errorlist"><li>\u041e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0435 \u043f\u043e\u043b\u0435.</li></ul>\n<p><label for="id_somechoice_0">\xc5\xf8\xdf</label> <ul>\n<li><label><input type="radio" id="id_somechoice_0" value="\xc5" name="somechoice" /> En tied\xe4</label></li>\n<li><label><input type="radio" id="id_somechoice_1" value="\xf8" name="somechoice" /> Mies</label></li>\n<li><label><input type="radio" id="id_somechoice_2" value="\xdf" name="somechoice" /> Nainen</label></li>\n</ul></p>'
    6161>>> deactivate()
    6262
    6363Deep copying translated text shouldn't raise an error
Back to Top