Skip to content
Projeler
Gruplar
Parçacıklar
Yardım
Yükleniyor...
Oturum aç / Kaydol
Gezinmeyi değiştir
D
django
Proje
Proje
Ayrıntılar
Etkinlik
Cycle Analytics
Depo (repository)
Depo (repository)
Dosyalar
Kayıtlar (commit)
Dallar (branch)
Etiketler
Katkıda bulunanlar
Grafik
Karşılaştır
Grafikler
Konular (issue)
0
Konular (issue)
0
Liste
Pano
Etiketler
Kilometre Taşları
Birleştirme (merge) Talepleri
0
Birleştirme (merge) Talepleri
0
CI / CD
CI / CD
İş akışları (pipeline)
İşler
Zamanlamalar
Grafikler
Paketler
Paketler
Wiki
Wiki
Parçacıklar
Parçacıklar
Üyeler
Üyeler
Collapse sidebar
Close sidebar
Etkinlik
Grafik
Grafikler
Yeni bir konu (issue) oluştur
İşler
Kayıtlar (commit)
Konu (issue) Panoları
Kenar çubuğunu aç
Batuhan Osman TASKAYA
django
Commits
2e4200b5
Kaydet (Commit)
2e4200b5
authored
Şub 13, 2014
tarafından
Loic Bistuer
Kaydeden (comit)
Tim Graham
Şub 14, 2014
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Fixed #21654 -- Documented a use-case for Form.errors.as_data().
Thanks selwin for the suggestion.
üst
007c5cd3
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
21 additions
and
0 deletions
+21
-0
api.txt
docs/ref/forms/api.txt
+14
-0
validation.txt
docs/ref/forms/validation.txt
+7
-0
No files found.
docs/ref/forms/api.txt
Dosyayı görüntüle @
2e4200b5
...
@@ -128,6 +128,20 @@ instances.
...
@@ -128,6 +128,20 @@ instances.
{'sender': [ValidationError(['Enter a valid email address.'])],
{'sender': [ValidationError(['Enter a valid email address.'])],
'subject': [ValidationError(['This field is required.'])]}
'subject': [ValidationError(['This field is required.'])]}
Use this method anytime you need to identify an error by its ``code``. This
enables things like rewriting the error's message or writing custom logic in a
view when a given error is present. It can also be used to serialize the errors
in a custom format (e.g. XML); for instance, :meth:`~Form.errors.as_json()`
relies on ``as_data()``.
The need for the ``as_data()`` method is due to backwards compatibility.
Previously ``ValidationError`` instances were lost as soon as their
**rendered** error messages were added to the ``Form.errors`` dictionary.
Ideally ``Form.errors`` would have stored ``ValidationError`` instances
and methods with an ``as_`` prefix could render them, but it had to be done
the other way around in order not to break code that expects rendered error
messages in ``Form.errors``.
.. method:: Form.errors.as_json()
.. method:: Form.errors.as_json()
.. versionadded:: 1.7
.. versionadded:: 1.7
...
...
docs/ref/forms/validation.txt
Dosyayı görüntüle @
2e4200b5
...
@@ -179,6 +179,13 @@ to override your error message you can still opt for the less verbose::
...
@@ -179,6 +179,13 @@ to override your error message you can still opt for the less verbose::
ValidationError(_('Invalid value: %s') % value)
ValidationError(_('Invalid value: %s') % value)
.. versionadded:: 1.7
The :meth:`Form.errors.as_data() <django.forms.Form.errors.as_data()>` and
:meth:`Form.errors.as_json() <django.forms.Form.errors.as_json()>` methods
greatly benefit from fully featured ``ValidationError``\s (with a ``code`` name
and a ``params`` dictionary).
Raising multiple errors
Raising multiple errors
~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~~~~~~~~
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment