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!