| | 2083 | If a label is set to the empty string for a field, that field won't get a label. |
|---|
| | 2084 | >>> class UserRegistration(Form): |
|---|
| | 2085 | ... username = CharField(max_length=10, label='') |
|---|
| | 2086 | ... password = CharField(widget=PasswordInput) |
|---|
| | 2087 | >>> p = UserRegistration(auto_id=False) |
|---|
| | 2088 | >>> print p.as_ul() |
|---|
| | 2089 | <li> <input type="text" name="username" maxlength="10" /></li> |
|---|
| | 2090 | <li>Password: <input type="password" name="password" /></li> |
|---|
| | 2091 | >>> p = UserRegistration(auto_id='id_%s') |
|---|
| | 2092 | >>> print p.as_ul() |
|---|
| | 2093 | <li> <input id="id_username" type="text" name="username" maxlength="10" /></li> |
|---|
| | 2094 | <li><label for="id_password">Password:</label> <input type="password" name="password" id="id_password" /></li> |
|---|
| | 2095 | |
|---|
| | 2096 | If label is None, Django will auto-create the label from the field name. This |
|---|
| | 2097 | is default behavior. |
|---|
| | 2098 | >>> class UserRegistration(Form): |
|---|
| | 2099 | ... username = CharField(max_length=10, label=None) |
|---|
| | 2100 | ... password = CharField(widget=PasswordInput) |
|---|
| | 2101 | >>> p = UserRegistration(auto_id=False) |
|---|
| | 2102 | >>> print p.as_ul() |
|---|
| | 2103 | <li>Username: <input type="text" name="username" maxlength="10" /></li> |
|---|
| | 2104 | <li>Password: <input type="password" name="password" /></li> |
|---|
| | 2105 | >>> p = UserRegistration(auto_id='id_%s') |
|---|
| | 2106 | >>> print p.as_ul() |
|---|
| | 2107 | <li><label for="id_username">Username:</label> <input id="id_username" type="text" name="username" maxlength="10" /></li> |
|---|
| | 2108 | <li><label for="id_password">Password:</label> <input type="password" name="password" id="id_password" /></li> |
|---|
| | 2109 | |
|---|