Django CSRF Token without forms

后端 未结 4 1256
天命终不由人
天命终不由人 2021-02-05 21:04

Sounds strange but what about the scenario posting contents with Javascript (for example AJAX) without using a form (could be possible to read several contents from the surface)

4条回答
  •  长发绾君心
    2021-02-05 22:06

    it is simple with this code:

    $.ajaxSetup({ data: {csrfmiddlewaretoken: '{{ csrf_token }}' },});
    

    see more: https://stackoverflow.com/a/7715325/1743582

提交回复
热议问题