Форма с ошибками

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
[root@lolka-desktop]:/var/python/my# python manage.py shell
Python 2.5.1 (r251:54863, May 2 2007, 16:56:35)
[GCC 4.1.2 (Ubuntu 4.1.2-0ubuntu4)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
(InteractiveConsole)
>>> from django import newforms as forms
>>> class MyForm(forms.Form):
... user = forms.CharField(max_length=100)
...
>>> data = {"user": "test"}
>>> f1 = MyForm(data)
>>> f1.is_valid()
True
>>> print f1
<tr><th><label for="id_user">User:</label></th><td><input id="id_user" type="text" name="user" value="test" maxlength="100" /></td></tr>
>>> data2 = {"user": ''}
>>> f2 = MyForm(data2)
>>> f2.is_valid()
False
>>> print f2
<tr><th><label for="id_user">User:</label></th><td><ul class="errorlist"><li>This field is required.</li></ul><input id="id_user" type="text" name="user" maxlength="100" /></td></tr>
>>>