Code

Opened 5 years ago

Closed 5 years ago

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

Download all attachments as: .zip

Change History (4)

Changed 5 years ago by brook

Simple test that prints out the errors of an invalid form

comment:1 Changed 5 years ago by brook

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

comment:2 follow-up: Changed 5 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 5 years ago by brook

Gotcha - that makes sense.

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.