Opened 6 years ago

Closed 6 years ago

Last modified 6 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: UI/UX:

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 6 years ago.
Simple test that prints out the errors of an invalid form

Download all attachments as: .zip

Change History (4)

Changed 6 years ago by brook

Simple test that prints out the errors of an invalid form

comment:1 Changed 6 years ago by brook

  • Cc bruscoob@… added
  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset

comment:2 follow-up: Changed 6 years ago by kmtracey

  • Resolution set to invalid
  • Status changed from new to closed

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>
>>>

comment:3 in reply to: ↑ 2 Changed 6 years ago by brook

Gotcha - that makes sense.

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