How to POST a django form with AJAX & jQuery

后端 未结 6 984
南方客
南方客 2020-11-28 00:49

I\'ve checked out tons of tutorials for django AJAX forms, but each one of them tells you one way of doing it, none of them is simple and I\'m a bit confused since I\'ve nev

6条回答
  •  甜味超标
    2020-11-28 01:24

    Most of examples of using AJAX POST with Django forms, including the official example:

    https://docs.djangoproject.com/en/1.9/topics/class-based-views/generic-editing/#ajax-example

    are fine when ModelForm.clean() did not produce any errors (form_valid). However, they do not perform hard part: translating ModelForm errors via AJAX response to Javascript / DOM client-side.

    My pluggable application uses AJAX response routing with client-side viewmodels to automatically display class-based view AJAX post ModelForm validation errors similar to how they would be displayed in traditional HTTP POST:

    https://django-jinja-knockout.readthedocs.org/en/latest/forms.html#ajax-forms-processing https://django-jinja-knockout.readthedocs.org/en/latest/viewmodels.html

    Both Jinja2 and Django Template Engine are supported.

提交回复
热议问题