Opened 15 years ago

Closed 15 years ago

Last modified 15 years ago

#11958 closed (invalid)

Form.errors returns an HTML unordered list, rather than a python dict object

Reported by: brook Owned by: nobody
Component: Documentation Version: 1.1
Severity: Keywords: dict list form errors
Cc: bruscoob@… Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

The documentation for Form.errors (http://docs.djangoproject.com/en/dev/ref/forms/api/#django.forms.Form.errors) says that Form.errors will return a python dict. Instead an html unordered list is returned.

Attachments (1)

contactform_errors.py (518 bytes ) - added by brook 15 years ago.
Simple test that prints out the errors of an invalid form

Download all attachments as: .zip

Change History (4)

by brook, 15 years ago

Attachment: contactform_errors.py added

Simple test that prints out the errors of an invalid form

comment:1 by brook, 15 years ago

Cc: bruscoob@… added

comment:2 by Karen Tracey, 15 years ago

Resolution: invalid
Status: newclosed

Your test prints the errors. This causes the errors dict to get converted to an HTML unordered list. See:

http://code.djangoproject.com/browser/django/tags/releases/1.1/django/forms/util.py#L14

If you access it directly instead of printing it, you will see it is a dict:

>>> import django
>>> django.get_version()
'1.1'
>>> from django import forms
>>> class SForm(forms.Form):
...    int = forms.IntegerField()
...
>>> sf = SForm({})
>>> sf.is_valid()
False
>>> sf.errors
{'int': [u'This field is required.']}
>>> print sf.errors
<ul class="errorlist"><li>int<ul class="errorlist"><li>This field is required.</li></ul></li></ul>
>>>

in reply to:  2 comment:3 by brook, 15 years ago

Gotcha - that makes sense.

Note: See TracTickets for help on using tickets.
Back to Top