Django

Code

Changeset 4192

Show
Ignore:
Timestamp:
12/10/06 20:38:18 (2 years ago)
Author:
adrian
Message:

newforms: Changed Form to use auto_id by default

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • django/trunk/django/newforms/forms.py

    r4188 r4192  
    3737    __metaclass__ = DeclarativeFieldsMetaclass 
    3838 
    39     def __init__(self, data=None, auto_id=False): # TODO: prefix stuff 
     39    def __init__(self, data=None, auto_id='id_%s'): # TODO: prefix stuff 
    4040        self.ignore_errors = data is None 
    4141        self.data = data or {} 
  • django/trunk/tests/regressiontests/forms/tests.py

    r4188 r4192  
    13281328{'first_name': u'John', 'last_name': u'Lennon', 'birthday': datetime.date(1940, 10, 9)} 
    13291329>>> print p['first_name'] 
    1330 <input type="text" name="first_name" value="John" /> 
     1330<input type="text" name="first_name" value="John" id="id_first_name" /> 
    13311331>>> print p['last_name'] 
    1332 <input type="text" name="last_name" value="Lennon" /> 
     1332<input type="text" name="last_name" value="Lennon" id="id_last_name" /> 
    13331333>>> print p['birthday'] 
    1334 <input type="text" name="birthday" value="1940-10-9" /> 
     1334<input type="text" name="birthday" value="1940-10-9" id="id_birthday" /> 
    13351335>>> for boundfield in p: 
    13361336...     print boundfield 
    1337 <input type="text" name="first_name" value="John" /> 
    1338 <input type="text" name="last_name" value="Lennon" /> 
    1339 <input type="text" name="birthday" value="1940-10-9" /> 
     1337<input type="text" name="first_name" value="John" id="id_first_name" /> 
     1338<input type="text" name="last_name" value="Lennon" id="id_last_name" /> 
     1339<input type="text" name="birthday" value="1940-10-9" id="id_birthday" /> 
    13401340>>> for boundfield in p: 
    13411341...     print boundfield.label, boundfield.data 
     
    13441344Birthday 1940-10-9 
    13451345>>> print p 
    1346 <tr><td>First name:</td><td><input type="text" name="first_name" value="John" /></td></tr> 
    1347 <tr><td>Last name:</td><td><input type="text" name="last_name" value="Lennon" /></td></tr> 
    1348 <tr><td>Birthday:</td><td><input type="text" name="birthday" value="1940-10-9" /></td></tr> 
     1346<tr><td><label for="id_first_name">First name:</label></td><td><input type="text" name="first_name" value="John" id="id_first_name" /></td></tr> 
     1347<tr><td><label for="id_last_name">Last name:</label></td><td><input type="text" name="last_name" value="Lennon" id="id_last_name" /></td></tr> 
     1348<tr><td><label for="id_birthday">Birthday:</label></td><td><input type="text" name="birthday" value="1940-10-9" id="id_birthday" /></td></tr> 
    13491349 
    13501350Empty dictionaries are valid, too. 
     
    13561356>>> print p 
    13571357<tr><td colspan="2"><ul class="errorlist"><li>This field is required.</li></ul></td></tr> 
    1358 <tr><td>First name:</td><td><input type="text" name="first_name" /></td></tr> 
     1358<tr><td><label for="id_first_name">First name:</label></td><td><input type="text" name="first_name" id="id_first_name" /></td></tr> 
    13591359<tr><td colspan="2"><ul class="errorlist"><li>This field is required.</li></ul></td></tr> 
    1360 <tr><td>Last name:</td><td><input type="text" name="last_name" /></td></tr> 
     1360<tr><td><label for="id_last_name">Last name:</label></td><td><input type="text" name="last_name" id="id_last_name" /></td></tr> 
    13611361<tr><td colspan="2"><ul class="errorlist"><li>This field is required.</li></ul></td></tr> 
    1362 <tr><td>Birthday:</td><td><input type="text" name="birthday" /></td></tr> 
     1362<tr><td><label for="id_birthday">Birthday:</label></td><td><input type="text" name="birthday" id="id_birthday" /></td></tr> 
    13631363>>> print p.as_table() 
    13641364<tr><td colspan="2"><ul class="errorlist"><li>This field is required.</li></ul></td></tr> 
    1365 <tr><td>First name:</td><td><input type="text" name="first_name" /></td></tr> 
     1365<tr><td><label for="id_first_name">First name:</label></td><td><input type="text" name="first_name" id="id_first_name" /></td></tr> 
    13661366<tr><td colspan="2"><ul class="errorlist"><li>This field is required.</li></ul></td></tr> 
    1367 <tr><td>Last name:</td><td><input type="text" name="last_name" /></td></tr> 
     1367<tr><td><label for="id_last_name">Last name:</label></td><td><input type="text" name="last_name" id="id_last_name" /></td></tr> 
    13681368<tr><td colspan="2"><ul class="errorlist"><li>This field is required.</li></ul></td></tr> 
    1369 <tr><td>Birthday:</td><td><input type="text" name="birthday" /></td></tr> 
     1369<tr><td><label for="id_birthday">Birthday:</label></td><td><input type="text" name="birthday" id="id_birthday" /></td></tr> 
    13701370>>> print p.as_ul() 
    1371 <li><ul class="errorlist"><li>This field is required.</li></ul>First name: <input type="text" name="first_name" /></li> 
    1372 <li><ul class="errorlist"><li>This field is required.</li></ul>Last name: <input type="text" name="last_name" /></li> 
    1373 <li><ul class="errorlist"><li>This field is required.</li></ul>Birthday: <input type="text" name="birthday" /></li> 
     1371<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> 
     1372<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> 
     1373<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> 
    13741374>>> print p.as_p() 
    13751375<p><ul class="errorlist"><li>This field is required.</li></ul></p> 
    1376 <p>First name: <input type="text" name="first_name" /></p> 
     1376<p><label for="id_first_name">First name:</label> <input type="text" name="first_name" id="id_first_name" /></p> 
    13771377<p><ul class="errorlist"><li>This field is required.</li></ul></p> 
    1378 <p>Last name: <input type="text" name="last_name" /></p> 
     1378<p><label for="id_last_name">Last name:</label> <input type="text" name="last_name" id="id_last_name" /></p> 
    13791379<p><ul class="errorlist"><li>This field is required.</li></ul></p> 
    1380 <p>Birthday: <input type="text" name="birthday" /></p> 
     1380<p><label for="id_birthday">Birthday:</label> <input type="text" name="birthday" id="id_birthday" /></p> 
    13811381 
    13821382If you don't pass any values to the Form's __init__(), or if you pass None, 
     
    13891389False 
    13901390>>> print p 
    1391 <tr><td>First name:</td><td><input type="text" name="first_name" /></td></tr> 
    1392 <tr><td>Last name:</td><td><input type="text" name="last_name" /></td></tr> 
    1393 <tr><td>Birthday:</td><td><input type="text" name="birthday" /></td></tr> 
     1391<tr><td><label for="id_first_name">First name:</label></td><td><input type="text" name="first_name" id="id_first_name" /></td></tr> 
     1392<tr><td><label for="id_last_name">Last name:</label></td><td><input type="text" name="last_name" id="id_last_name" /></td></tr> 
     1393<tr><td><label for="id_birthday">Birthday:</label></td><td><input type="text" name="birthday" id="id_birthday" /></td></tr> 
    13941394>>> print p.as_table() 
    1395 <tr><td>First name:</td><td><input type="text" name="first_name" /></td></tr> 
    1396 <tr><td>Last name:</td><td><input type="text" name="last_name" /></td></tr> 
    1397 <tr><td>Birthday:</td><td><input type="text" name="birthday" /></td></tr> 
     1395<tr><td><label for="id_first_name">First name:</label></td><td><input type="text" name="first_name" id="id_first_name" /></td></tr> 
     1396<tr><td><label for="id_last_name">Last name:</label></td><td><input type="text" name="last_name" id="id_last_name" /></td></tr> 
     1397<tr><td><label for="id_birthday">Birthday:</label></td><td><input type="text" name="birthday" id="id_birthday" /></td></tr> 
    13981398>>> print p.as_ul() 
    1399 <li>First name: <input type="text" name="first_name" /></li> 
    1400 <li>Last name: <input type="text" name="last_name" /></li> 
    1401 <li>Birthday: <input type="text" name="birthday" /></li> 
     1399<li><label for="id_first_name">First name:</label> <input type="text" name="first_name" id="id_first_name" /></li> 
     1400<li><label for="id_last_name">Last name:</label> <input type="text" name="last_name" id="id_last_name" /></li> 
     1401<li><label for="id_birthday">Birthday:</label> <input type="text" name="birthday" id="id_birthday" /></li> 
    14021402>>> print p.as_p() 
    1403 <p>First name: <input type="text" name="first_name" /></p> 
    1404 <p>Last name: <input type="text" name="last_name" /></p> 
    1405 <p>Birthday: <input type="text" name="birthday" /></p> 
     1403<p><label for="id_first_name">First name:</label> <input type="text" name="first_name" id="id_first_name" /></p> 
     1404<p><label for="id_last_name">Last name:</label> <input type="text" name="last_name" id="id_last_name" /></p> 
     1405<p><label for="id_birthday">Birthday:</label> <input type="text" name="birthday" id="id_birthday" /></p> 
    14061406 
    14071407Unicode values are handled properly. 
    14081408>>> p = Person({'first_name': u'John', 'last_name': u'\u0160\u0110\u0106\u017d\u0107\u017e\u0161\u0111', 'birthday': '1940-10-9'}) 
    14091409>>> p.as_table() 
    1410 u'<tr><td>First name:</td><td><input type="text" name="first_name" value="John" /></td></tr>\n<tr><td>Last name:</td><td><input type="text" name="last_name" value="\u0160\u0110\u0106\u017d\u0107\u017e\u0161\u0111" /></td></tr>\n<tr><td>Birthday:</td><td><input type="text" name="birthday" value="1940-10-9" /></td></tr>' 
     1410u'<tr><td><label for="id_first_name">First name:</label></td><td><input type="text" name="first_name" value="John" id="id_first_name" /></td></tr>\n<tr><td><label for="id_last_name">Last name:</label></td><td><input type="text" name="last_name" value="\u0160\u0110\u0106\u017d\u0107\u017e\u0161\u0111" id="id_last_name" /></td></tr>\n<tr><td><label for="id_birthday">Birthday:</label></td><td><input type="text" name="birthday" value="1940-10-9" id="id_birthday" /></td></tr>' 
    14111411>>> p.as_ul() 
    1412 u'<li>First name: <input type="text" name="first_name" value="John" /></li>\n<li>Last name: <input type="text" name="last_name" value="\u0160\u0110\u0106\u017d\u0107\u017e\u0161\u0111" /></li>\n<li>Birthday: <input type="text" name="birthday" value="1940-10-9" /></li>' 
     1412u'<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>' 
    14131413>>> p.as_p() 
    1414 u'<p>First name: <input type="text" name="first_name" value="John" /></p>\n<p>Last name: <input type="text" name="last_name" value="\u0160\u0110\u0106\u017d\u0107\u017e\u0161\u0111" /></p>\n<p>Birthday: <input type="text" name="birthday" value="1940-10-9" /></p>' 
     1414u'<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>' 
    14151415 
    14161416>>> p = Person({'last_name': u'Lennon'}) 
     
    14381438>>> p = Person() 
    14391439>>> print p['first_name'] 
    1440 <input type="text" name="first_name" /> 
     1440<input type="text" name="first_name" id="id_first_name" /> 
    14411441>>> print p['last_name'] 
    1442 <input type="text" name="last_name" /> 
     1442<input type="text" name="last_name" id="id_last_name" /> 
    14431443>>> print p['birthday'] 
    1444 <input type="text" name="birthday" /> 
     1444<input type="text" name="birthday" id="id_birthday" /> 
    14451445 
    14461446"auto_id" tells the Form to add an "id" attribute to each form element. 
     
    14481448into which the field's name will be inserted. It will also put a <label> around 
    14491449the human-readable labels for a field. 
    1450 >>> p = Person(auto_id='id_%s') 
     1450>>> p = Person(auto_id='%s_id') 
    14511451>>> print p.as_table() 
    1452 <tr><td><label for="id_first_name">First name:</label></td><td><input type="text" name="first_name" id="id_first_name" /></td></tr> 
    1453 <tr><td><label for="id_last_name">Last name:</label></td><td><input type="text" name="last_name" id="id_last_name" /></td></tr> 
    1454 <tr><td><label for="id_birthday">Birthday:</label></td><td><input type="text" name="birthday" id="id_birthday" /></td></tr> 
     1452<tr><td><label for="first_name_id">First name:</label></td><td><input type="text" name="first_name" id="first_name_id" /></td></tr> 
     1453<tr><td><label for="last_name_id">Last name:</label></td><td><input type="text" name="last_name" id="last_name_id" /></td></tr> 
     1454<tr><td><label for="birthday_id">Birthday:</label></td><td><input type="text" name="birthday" id="birthday_id" /></td></tr> 
    14551455>>> print p.as_ul() 
    1456 <li><label for="id_first_name">First name:</label> <input type="text" name="first_name" id="id_first_name" /></li> 
    1457 <li><label for="id_last_name">Last name:</label> <input type="text" name="last_name" id="id_last_name" /></li> 
    1458 <li><label for="id_birthday">Birthday:</label> <input type="text" name="birthday" id="id_birthday" /></li> 
     1456<li><label for="first_name_id">First name:</label> <input type="text" name="first_name" id="first_name_id" /></li> 
     1457<li><label for="last_name_id">Last name:</label> <input type="text" name="last_name" id="last_name_id" /></li> 
     1458<li><label for="birthday_id">Birthday:</label> <input type="text" name="birthday" id="birthday_id" /></li> 
    14591459>>> print p.as_p() 
    1460 <p><label for="id_first_name">First name:</label> <input type="text" name="first_name" id="id_first_name" /></p> 
    1461 <p><label for="id_last_name">Last name:</label> <input type="text" name="last_name" id="id_last_name" /></p> 
    1462 <p><label for="id_birthday">Birthday:</label> <input type="text" name="birthday" id="id_birthday" /></p> 
     1460<p><label for="first_name_id">First name:</label> <input type="text" name="first_name" id="first_name_id" /></p> 
     1461<p><label for="last_name_id">Last name:</label> <input type="text" name="last_name" id="last_name_id" /></p> 
     1462<p><label for="birthday_id">Birthday:</label> <input type="text" name="birthday" id="birthday_id" /></p> 
    14631463 
    14641464If auto_id is any True value whose str() does not contain '%s', the "id" 
     
    15011501...     email = EmailField() 
    15021502...     get_spam = BooleanField() 
    1503 >>> f = SignupForm(
     1503>>> f = SignupForm(auto_id=False
    15041504>>> print f['email'] 
    15051505<input type="text" name="email" /> 
     
    15071507<input type="checkbox" name="get_spam" /> 
    15081508 
    1509 >>> f = SignupForm({'email': 'test@example.com', 'get_spam': True}
     1509>>> f = SignupForm({'email': 'test@example.com', 'get_spam': True}, auto_id=False
    15101510>>> print f['email'] 
    15111511<input type="text" name="email" value="test@example.com" /> 
     
    15171517...     subject = CharField() 
    15181518...     message = CharField(widget=Textarea) 
    1519 >>> f = ContactForm(
     1519>>> f = ContactForm(auto_id=False
    15201520>>> print f['subject'] 
    15211521<input type="text" name="subject" /> 
     
    15361536...     subject = CharField() 
    15371537...     message = CharField(widget=Textarea(attrs={'rows': 80, 'cols': 20})) 
    1538 >>> f = ContactForm(
     1538>>> f = ContactForm(auto_id=False
    15391539>>> print f['message'] 
    15401540<textarea rows="80" cols="20" name="message"></textarea> 
     
    15441544>>> f['message'].as_text() 
    15451545u'<input type="text" name="message" />' 
    1546 >>> f = ContactForm({'subject': 'Hello', 'message': 'I love you.'}
     1546>>> f = ContactForm({'subject': 'Hello', 'message': 'I love you.'}, auto_id=False
    15471547>>> f['subject'].as_textarea() 
    15481548u'<textarea name="subject">Hello</textarea>' 
     
    15561556...     name = CharField() 
    15571557...     language = ChoiceField(choices=[('P', 'Python'), ('J', 'Java')]) 
    1558 >>> f = FrameworkForm(
     1558>>> f = FrameworkForm(auto_id=False
    15591559>>> print f['language'] 
    15601560<select name="language"> 
     
    15621562<option value="J">Java</option> 
    15631563</select> 
    1564 >>> f = FrameworkForm({'name': 'Django', 'language': 'P'}
     1564>>> f = FrameworkForm({'name': 'Django', 'language': 'P'}, auto_id=False
    15651565>>> print f['language'] 
    15661566<select name="language"> 
     
    15731573...     name = CharField() 
    15741574...     language = ChoiceField(choices=[('P', 'Python'), ('J', 'Java')], widget=RadioSelect) 
    1575 >>> f = FrameworkForm(
     1575>>> f = FrameworkForm(auto_id=False
    15761576>>> print f['language'] 
    15771577<ul> 
     
    16281628...     name = CharField() 
    16291629...     composers = MultipleChoiceField() 
    1630 >>> f = SongForm(
     1630>>> f = SongForm(auto_id=False
    16311631>>> print f['composers'] 
    16321632<select multiple="multiple" name="composers"> 
     
    16351635...     name = CharField() 
    16361636...     composers = MultipleChoiceField(choices=[('J', 'John Lennon'), ('P', 'Paul McCartney')]) 
    1637 >>> f = SongForm(
     1637>>> f = SongForm(auto_id=False
    16381638>>> print f['composers'] 
    16391639<select multiple="multiple" name="composers"> 
     
    16411641<option value="P">Paul McCartney</option> 
    16421642</select> 
    1643 >>> f = SongForm({'name': 'Yesterday', 'composers': ['P']}
     1643>>> f = SongForm({'name': 'Yesterday', 'composers': ['P']}, auto_id=False
    16441644>>> print f['name'] 
    16451645<input type="text" name="name" value="Yesterday" /> 
     
    16541654...     name = CharField() 
    16551655...     composers = MultipleChoiceField(choices=[('J', 'John Lennon'), ('P', 'Paul McCartney')], widget=CheckboxSelectMultiple) 
    1656 >>> f = SongForm(
     1656>>> f = SongForm(auto_id=False
    16571657>>> print f['composers'] 
    16581658<ul> 
     
    16601660<li><label><input type="checkbox" name="composers" value="P" /> Paul McCartney</label></li> 
    16611661</ul> 
    1662 >>> f = SongForm({'composers': ['J']}
     1662>>> f = SongForm({'composers': ['J']}, auto_id=False
    16631663>>> print f['composers'] 
    16641664<ul> 
     
    16661666<li><label><input type="checkbox" name="composers" value="P" /> Paul McCartney</label></li> 
    16671667</ul> 
    1668 >>> f = SongForm({'composers': ['J', 'P']}
     1668>>> f = SongForm({'composers': ['J', 'P']}, auto_id=False
    16691669>>> print f['composers'] 
    16701670<ul> 
     
    16751675When using CheckboxSelectMultiple, the framework expects a list of input and 
    16761676returns a list of input. 
    1677 >>> f = SongForm({'name': 'Yesterday'}
     1677>>> f = SongForm({'name': 'Yesterday'}, auto_id=False
    16781678>>> f.errors 
    16791679{'composers': [u'This field is required.']} 
    1680 >>> f = SongForm({'name': 'Yesterday', 'composers': ['J']}
     1680>>> f = SongForm({'name': 'Yesterday', 'composers': ['J']}, auto_id=False
    16811681>>> f.errors 
    16821682{} 
    16831683>>> f.clean_data 
    16841684{'composers': [u'J'], 'name': u'Yesterday'} 
    1685 >>> f = SongForm({'name': 'Yesterday', 'composers': ['J', 'P']}
     1685>>> f = SongForm({'name': 'Yesterday', 'composers': ['J', 'P']}, auto_id=False
    16861686>>> f.errors 
    16871687{} 
     
    17041704...            raise ValidationError(u'Please make sure your passwords match.') 
    17051705...        return self.clean_data['password2'] 
    1706 >>> f = UserRegistration(
     1706>>> f = UserRegistration(auto_id=False
    17071707>>> f.errors 
    17081708{} 
    1709 >>> f = UserRegistration({}
     1709>>> f = UserRegistration({}, auto_id=False
    17101710>>> f.errors 
    17111711{'username': [u'This field is required.'], 'password1': [u'This field is required.'], 'password2': [u'This field is required.']} 
    1712 >>> f = UserRegistration({'username': 'adrian', 'password1': 'foo', 'password2': 'bar'}
     1712>>> f = UserRegistration({'username': 'adrian', 'password1': 'foo', 'password2': 'bar'}, auto_id=False
    17131713>>> f.errors 
    17141714{'password2': [u'Please make sure your passwords match.']} 
    1715 >>> f = UserRegistration({'username': 'adrian', 'password1': 'foo', 'password2': 'foo'}
     1715>>> f = UserRegistration({'username': 'adrian', 'password1': 'foo', 'password2': 'foo'}, auto_id=False
    17161716>>> f.errors 
    17171717{} 
     
    17341734...            raise ValidationError(u'Please make sure your passwords match.') 
    17351735...        return self.clean_data 
    1736 >>> f = UserRegistration(
     1736>>> f = UserRegistration(auto_id=False
    17371737>>> f.errors 
    17381738{} 
    1739 >>> f = UserRegistration({}
     1739>>> f = UserRegistration({}, auto_id=False
    17401740>>> print f.as_table() 
    17411741<tr><td colspan="2"><ul class="errorlist"><li>This field is required.</li></ul></td></tr> 
     
    17471747>>> f.errors 
    17481748{'username': [u'This field is required.'], 'password1': [u'This field is required.'], 'password2': [u'This field is required.']} 
    1749 >>> f = UserRegistration({'username': 'adrian', 'password1': 'foo', 'password2': 'bar'}
     1749>>> f = UserRegistration({'username': 'adrian', 'password1': 'foo', 'password2': 'bar'}, auto_id=False
    17501750>>> f.errors 
    17511751{'__all__': [u'Please make sure your passwords match.']} 
     
    17601760<li>Password1: <input type="password" name="password1" value="foo" /></li> 
    17611761<li>Password2: <input type="password" name="password2" value="bar" /></li> 
    1762 >>> f = UserRegistration({'username': 'adrian', 'password1': 'foo', 'password2': 'foo'}
     1762>>> f = UserRegistration({'username': 'adrian', 'password1': 'foo', 'password2': 'foo'}, auto_id=False
    17631763>>> f.errors 
    17641764{} 
     
    17721772...     first_name = CharField() 
    17731773...     last_name = CharField() 
    1774 ...     def __init__(self): 
    1775 ...         super(Person, self).__init__(
     1774...     def __init__(self, *args, **kwargs): 
     1775...         super(Person, self).__init__(*args, **kwargs
    17761776...         self.fields['birthday'] = DateField() 
    1777 >>> p = Person(
     1777>>> p = Person(auto_id=False
    17781778>>> print p 
    17791779<tr><td>First name:</td><td><input type="text" name="first_name" /></td></tr> 
     
    17901790...     hidden_text = CharField(widget=HiddenInput) 
    17911791...     birthday = DateField() 
    1792 >>> p = Person(
     1792>>> p = Person(auto_id=False
    17931793>>> print p 
    17941794<tr><td>First name:</td><td><input type="text" name="first_name" /></td></tr> 
     
    18231823prepended. This message is displayed at the top of the output, regardless of 
    18241824its field's order in the form. 
    1825 >>> p = Person({'first_name': 'John', 'last_name': 'Lennon', 'birthday': '1940-10-9'}
     1825>>> p = Person({'first_name': 'John', 'last_name': 'Lennon', 'birthday': '1940-10-9'}, auto_id=False
    18261826>>> print p 
    18271827<tr><td colspan="2"><ul class="errorlist"><li>(Hidden field hidden_text) This field is required.</li></ul></td></tr> 
     
    18441844...     foo = CharField(widget=HiddenInput) 
    18451845...     bar = CharField(widget=HiddenInput) 
    1846 >>> p = TestForm(
     1846>>> p = TestForm(auto_id=False
    18471847>>> print p.as_table() 
    18481848<input type="hidden" name="foo" /><input type="hidden" name="bar" /> 
     
    18681868...     field13 = CharField() 
    18691869...     field14 = CharField() 
    1870 >>> p = TestForm(
     1870>>> p = TestForm(auto_id=False
    18711871>>> print p 
    18721872<tr><td>Field1:</td><td><input type="text" name="field1" /></td></tr> 
     
    18941894...    realname = CharField(max_length=10, widget=TextInput) # redundantly define widget, just to test 
    18951895...    address = CharField()                                 # no max_length defined here 
    1896 >>> p = UserRegistration(
     1896>>> p = UserRegistration(auto_id=False
    18971897>>> print p.as_ul() 
    18981898<li>Username: <input type="text" name="username" maxlength="10" /></li> 
     
    19071907...    username = CharField(max_length=10, widget=TextInput(attrs={'maxlength': 20})) 
    19081908...    password = CharField(max_length=10, widget=PasswordInput) 
    1909 >>> p = UserRegistration(
     1909>>> p = UserRegistration(auto_id=False
    19101910>>> print p.as_ul() 
    19111911<li>Username: <input type="text" name="username" maxlength="10" /></li> 
     
    19191919...    password1 = CharField(widget=PasswordInput) 
    19201920...    password2 = CharField(widget=PasswordInput, label='Password (again)') 
    1921 >>> p = UserRegistration(
     1921>>> p = UserRegistration(auto_id=False
    19221922>>> print p.as_ul() 
    19231923<li>Your username: <input type="text" name="username" maxlength="10" /></li> 
     
    19381938>>> def my_function(method, post_data): 
    19391939...     if method == 'POST': 
    1940 ...         form = UserRegistration(post_data
     1940...         form = UserRegistration(post_data, auto_id=False
    19411941...     else: 
    1942 ...         form = UserRegistration(
     1942...         form = UserRegistration(auto_id=False
    19431943...     if form.is_valid(): 
    19441944...         return 'VALID: %r' % form.clean_data 
     
    19961996... <input type="submit" /> 
    19971997... </form>''') 
    1998 >>> print t.render(Context({'form': UserRegistration()})) 
     1998>>> print t.render(Context({'form': UserRegistration(auto_id=False)})) 
    19991999<form action=""> 
    20002000<p><label>Your username: <input type="text" name="username" maxlength="10" /></label></p> 
     
    20032003<input type="submit" /> 
    20042004</form> 
    2005 >>> print t.render(Context({'form': UserRegistration({'username': 'django'})})) 
     2005>>> print t.render(Context({'form': UserRegistration({'username': 'django'}, auto_id=False)})) 
    20062006<form action=""> 
    20072007<p><label>Your username: <input type="text" name="username" value="django" maxlength="10" /></label></p> 
     
    20212021... <input type="submit" /> 
    20222022... </form>''') 
    2023 >>> print t.render(Context({'form': UserRegistration()})) 
     2023>>> print t.render(Context({'form': UserRegistration(auto_id=False)})) 
    20242024<form action=""> 
    20252025<p><label>Username: <input type="text" name="username" maxlength="10" /></label></p> 
     
    20392039... <input type="submit" /> 
    20402040... </form>''') 
    2041 >>> print t.render(Context({'form': UserRegistration()})) 
     2041>>> print t.render(Context({'form': UserRegistration(auto_id=False)})) 
    20422042<form action=""> 
    20432043<p>Username: <input type="text" name="username" maxlength="10" /></p> 
     
    20642064... <input type="submit" /> 
    20652065... </form>''') 
    2066 >>> print t.render(Context({'form': UserRegistration({'username': 'django', 'password1': 'foo', 'password2': 'bar'})})) 
     2066>>> print t.render(Context({'form': UserRegistration({'username': 'django', 'password1': 'foo', 'password2': 'bar'}, auto_id=False)})) 
    20672067<form action=""> 
    20682068<p><label>Your username: <input type="text" name="username" value="django" maxlength="10" /></label></p> 
     
    20782078... <input type="submit" /> 
    20792079... </form>''') 
    2080 >>> print t.render(Context({'form': UserRegistration({'username': 'django', 'password1': 'foo', 'password2': 'bar'})})) 
     2080>>> print t.render(Context({'form': UserRegistration({'username': 'django', 'password1': 'foo', 'password2': 'bar'}, auto_id=False)})) 
    20812081<form action=""> 
    20822082<ul class="errorlist"><li>Please make sure your passwords match.</li></ul>