mirror of
https://github.com/django/django.git
synced 2025-08-04 19:08:28 +00:00
Fixed #17413 -- Serialization of form errors along with all metadata.
This commit is contained in:
parent
e2f142030b
commit
3ce9829b61
8 changed files with 129 additions and 20 deletions
|
@ -117,6 +117,27 @@ The validation routines will only get called once, regardless of how many times
|
|||
you access :attr:`~Form.errors` or call :meth:`~Form.is_valid`. This means that
|
||||
if validation has side effects, those side effects will only be triggered once.
|
||||
|
||||
.. method:: Form.errors.as_data()
|
||||
|
||||
.. versionadded:: 1.7
|
||||
|
||||
Returns a ``dict`` that maps fields to their original ``ValidationError``
|
||||
instances.
|
||||
|
||||
>>> f.errors.as_data()
|
||||
{'sender': [ValidationError(['Enter a valid email address.'])],
|
||||
'subject': [ValidationError(['This field is required.'])]}
|
||||
|
||||
.. method:: Form.errors.as_json()
|
||||
|
||||
.. versionadded:: 1.7
|
||||
|
||||
Returns the errors serialized as JSON.
|
||||
|
||||
>>> f.errors.as_json()
|
||||
{"sender": [{"message": "Enter a valid email address.", "code": "invalid"}],
|
||||
"subject": [{"message": "This field is required.", "code": "required"}]}
|
||||
|
||||
.. method:: Form.add_error(field, error)
|
||||
|
||||
.. versionadded:: 1.7
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue