前端ajax访问 django 报错 POST http://127.0.0.1:8001/xxx 403 (Forbidden)

前端使用 ajax 访问后端 django 程序 报错误: POST http://127.0.0.1:8001/xxx 403 (Forbidden)

错误原因: 参数中未携带 csrfmiddlewaretoken

解决方案:

在前端页面中设置

 {% csrf_token %}

ajax 访问参数中设置

$.ajax({
    url: ‘http://127.0.0.1:8001/xxx‘,
    method: ‘post‘,
    data: {
        ‘csrfmiddlewaretoken‘: $("[name=‘csrfmiddlewaretoken‘]").val(),
    }, success:function (data) {    console.log(data);
    }, error:function (data){    console.log("访问失败!")  };

原文地址:https://www.cnblogs.com/chaoqi/p/10926984.html

时间: 2024-08-29 01:00:06

前端ajax访问 django 报错 POST http://127.0.0.1:8001/xxx 403 (Forbidden)的相关文章

flask+sqlite3+echarts2+ajax数据可视化报错:UnicodeDecodeError: 'utf8' codec can't decode byte解决方法

flask+sqlite3+echarts2+ajax数据可视化报错: UnicodeDecodeError: 'utf8' codec can't decode byte 解决方法: 将 py文件和html文件用用记事本打开,然后另存为,将编码ANSI改成:UTF-8 flask+sqlite3+echarts2+ajax数据可视化报错:UnicodeDecodeError: 'utf8' codec can't decode byte解决方法

Tomcat启动后访问首页报错 显示JSP 空指针异常

HTTP Status 500 - type Exception report message description The server encountered an internal error () that prevented it from fulfilling this request. exception org.apache.jasper.JasperException: java.lang.NullPointerException org.apache.jasper.serv

dede在使用session共享会话后,dede后台无法访问,报错500

dede在使用session共享会话后,dede后台无法访问,报错500: 解决方法: 修改文件一: vim /application/nginx/html/www/include/common.inc.php 137 //$sessSavePath = DEDEDATA."/sessions_{$enkey}"; 138 $sessSavePath = "tcp://172.16.1.7:11211";            --172.16.1.7 ,memca

Django报错 No module named 'django.templates'

前言 Django 模板报错了 修改方法: 将你的工程文件下(my_site)的settings.py中的TEMPLATES中的templates字段全部改为template, 亲测可用~^~ Django报错 No module named 'django.templates' 原文地址:https://www.cnblogs.com/yf-html/p/9314280.html

hue中访问hdfs报错

在hue中访问hdfs报错: Cannot access: /. Note: you are a Hue admin but not a HDFS superuser, "hdfs" or part of HDFS supergroup, "supergroup". 原因: 解决方法: 原文地址:https://www.cnblogs.com/mediocreWorld/p/11148875.html

hue中访问impala报错

hue中访问impala报错:Could not connect to node03:21050 原因:impala服务未启动. 解决方法:在3个节点上都启动impala: 主节点node03启动以下三个服务进程 service impala-state-store start service impala-catalog start service impala-server start 从节点启动node01与node02启动impala-server service  impala-ser

前端控制台 JavaScript函数报错 SyntaxError: expected expression, got ';' SyntaxError: expected expression, got 'if'

在火狐浏览器下调试时, 页面报错SyntaxError: expected expression, got ';'或者SyntaxError: expected expression, got 'if'等 其实就是js部分某个变量没有赋值到,例如: // 这种echo在前端输出的是空 var test = <?php echo 1 > 0 ? true : false ?>; 在前端js显示的是: var test = ; 注意: 在前端 test = ; 这样的变量没有赋值到就会报错,

django.core.exceptions.ImproperlyConfigured: mysqlclient 1.3.13 or newer is required; you have 0.9.3. | Django报错

Django报错 | "django.core.exceptions.ImproperlyConfigured: mysqlclient 1.3.13 or newer is required; you have 0.9.3.问题解决方案 1 问题分析 django.core.exceptions.ImproperlyConfigured: mysqlclient 1.3.13 or newer is required; you have 0.9.3. 解读:django.core.except

myeclipse关于svn更新报错:OPTIONS of &#39;/svn/Xxx&#39;: 403 Forbidden

这个问题出现原因是其他人修改了我原本写作的代码位置,把两个类转移到了别的文件夹,我更新之后只显示除了他增加的文件夹而没有里面的类,同时爆出错误: 问题原因:svn版本号不匹配,即跳版本. 解决如下:replace with --> 分支/标记 替换成最新版本即可. 借鉴网址:http://blog.sina.com.cn/s/blog_5ec46fd80102uwph.html myeclipse关于svn更新报错:OPTIONS of '/svn/Xxx': 403 Forbidden