码迷,mamicode.com
首页 > 其他好文 > 详细

django中csrf_token处理方式

时间:2019-06-05 19:49:41      阅读:145      评论:0      收藏:0      [点我收藏+]

标签:方式   UNC   ade   html   csrf   color   OLE   div   console   

第一:先在HTML中加入{% csrf_token %}

$.ajax({
    url: ‘{% url "ceshi:list" %}‘,
    type: ‘post‘,
    dataType: ‘json‘,
    cache: false,
    data: {
        key: "11111",
        csrfmiddlewaretoken: $(‘[name="csrfmiddlewaretoken"]‘).val()
},

success: function(obj)
{
    console.log("hello")
}
});

第二:先在HTML中加入{% csrf_token %}

$.ajax({
    url: ‘{% url "ceshi:list" %}‘,
    type: ‘post‘,
    dataType: ‘json‘,
    cache: false,
    headers: {"X-CSRFToken": $(‘[name="csrfmiddlewaretoken"]‘).val()},
    data: {
        key: "11111",
    },

    success: function(obj)
    {
        console.log("hello")
    }
});

 

django中csrf_token处理方式

标签:方式   UNC   ade   html   csrf   color   OLE   div   console   

原文地址:https://www.cnblogs.com/weilaibuxiangshuo/p/10981369.html

踩
(0)
赞
(0)
   
举报
评论 一句话评论(0)
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!