6、Django设置csrf_token
Ajax请求设置csrf_token
方式一
$.ajax({
url: "/cookie_ajax/",
type: "POST",
data: {
"username": "yang",
"password": 123,
// 使用jQuery取出csrfmiddlewaretoken的值,拼接到data总
"csrfmiddlewaretoken": $("[name="csrfmiddlewaretoken"]").val()
},
success: function(data){
console.log(data);
}
})方式二
如何取消 csrf_exempt
基于类
方法一:在类的 dispatch 方法上使用 @csrf_exempt
方法二:在 urls.py 中配置
基于视图
Last updated