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.

Summary

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!

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: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.