django中template中post请求接口csrf问题

编程入门 行业动态 更新时间:2024-10-20 03:21:33

django中template中post请求<a href=https://www.elefans.com/category/jswz/34/1771365.html style=接口csrf问题"/>

django中template中post请求接口csrf问题

$(function () {$.ajaxSetup({headers: { "X-CSRFToken": getCookie("csrftoken") }});
});// 为防止CSRF(Cross-site request forgery)跨站请求伪造,发post请求时需要在cookie中创建随机码
function getCookie(name)
{var arr,reg=new RegExp("(^| )"+name+"=([^;]*)(;|$)");/*上面这句话相当于:var arr;var reg=new RegExp("(^| )"+name+"=([^;]*)(;|$)");*/if(arr=document.cookie.match(reg))return decodeURI(arr[2]);  //ECMAScript v3 已从标准中删除了 unescape() 函数,并反对使用它,// 因此应该用 decodeURI() 和 decodeURIComponent() 取而代之。elsereturn null;
}

参考:
.htm?tdsourcetag=s_pcqq_aiomsg

更多推荐

django中template中post请求接口csrf问题

本文发布于:2023-12-08 12:07:21,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1672738.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:接口   template   django   csrf   post

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!