Django obtains the implementation of complex ajax post objects, and django obtains ajaxpost

Source: Internet
Author: User

Django obtains the implementation of complex ajax post objects, and django obtains ajaxpost

1. The post object in django's request is empty (that is, the post object transmitted by the front-end ajax cannot be obtained)

1. Comment out django. middleware. csrf. CsrfViewMiddleware in django's setting.

2. Add {% csrf %} to the from, and add the syntax sugar to the method accepted in the background: @ csrf_exempt. Note that the reference module is added.

3. If the preceding operations still fail, remove the action attribute in the form tag (this is only for ajax processing and not for form submission)

2. Complex ajax objects, such as [{"id": "001", "name": "James" },{ "id": "002 ", "name": "Xiaojun"}]., post Processing in the background

This type of object must be converted to json format and uploaded to the background for deserialization. (Do not use other ajax serialization formats. It is difficult to parse django background after deep serialization)

ContentType does not need to be specified with UTF-8; otherwise, an error occurs in post parsing (comment out, do not need to be left)

For the principle of post object parsing in csrf and django request, it will be supplemented later.


The above section describes how to implement django's complex post object for ajax. I hope it will be helpful to you. If you have any questions, please leave a message for me, the editor will reply to you in a timely manner. Thank you very much for your support for the help House website!

Related Article

E-Commerce Solutions

Leverage the same tools powering the Alibaba Ecosystem

Learn more >

11.11 Big Sale for Cloud

Get Unbeatable Offers with up to 90% Off,Oct.24-Nov.13 (UTC+8)

Get It Now >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.