Forbidden (CSRF token missing or incorrect.):错误解决办法

在JS中,使用post方法提交数据到后台,出现错误:

Forbidden (CSRF token missing or incorrect.):.........;

解决办法:

在页面导入JS的位置,补上以下代码即可:

1      <script>
2         $.ajaxSetup({
3             data:{csrfmiddlewaretoken:‘{{ csrf_token }}‘}
4         })
5     </script>

原文地址:https://www.cnblogs.com/lhb-alan/p/11372995.html

时间: 2024-11-09 05:00:04

Forbidden (CSRF token missing or incorrect.):错误解决办法的相关文章

关于 DjangoUeditor 上传图片图片失败,csrf token missing or incorrect 的解决办法

Forbidden (CSRF token missing or incorrect.): /ueditor/controller/ [27/Jun/2017 23:49:25] "POST /ueditor/controller/?imagePathFormat=courses%2Fueditor%2F&filePathFormat=courses%2Fueditor%2F&action=uploadvideo&encode=utf-8 HTTP/1.1" 4

&quot;CSRF token missing or incorrect.&quot;的解决方法.

现象: Forbidden (403)CSRF verification failed. Request aborted.HelpReason given for failure:CSRF token missing or incorrect. In general, this can occur when there is a genuine Cross Site Request Forgery, or when Django's CSRF mechanism has not been use

djangopost请求报错:Forbidden (CSRF token missing or incorrect.)

解决办法:引入csrf_exempt包: from django.views.decorators.csrf import csrf_exempt 然后增加装饰器: @csrf_exempt def register(request): request.encoding='utf-8' if request.GET: return render(request,'register.html') elif request.POST: dictData = request.POST context

解决django出现CSRF token missing or incorrect.错误

给template中的每个POST form添加{% csrf_token %}标签. <form action="/contact/" method="post">     {% csrf_token %}     <p>Subject: <input type="text" name="subject"></p>     <p>Your e-mail (optio

Forbidden (CSRF token missing or incorrect.):

CSRF令牌失效或丢失,Ajax请求页面报错(403 Forbidden ) csrftoken存在 页面响应为CSRF验证失败请求被中断,经过测试,该错误并非是没有在表单中加入{% csrf_token%} 导致[试过] 刷新dns缓存依然无法解决该问题, 解决: 检查setting配置中 'django.middleware.csrf.CsrfViewMiddleware', 在浏览器隐私中清除cookie,[无效] 刷新dns[无效] 最后解决方案: 在引用js之前加入Ajax启动项,之前

ajax $.post 一直报 Forbidden (CSRF token missing or incorrect.)

由于后台整合类视图代码,所以修改了写法,完了之后用下面的写法写的post请求都报 403 error $.post( "{% url 'test_record:select_node_page' ret.uut_id %}", { // uut_id: "{{ ret.uut_id }}", filter: JSON.stringify(filters), }, function(data){ var retData = JSON.parse(data); cons

django出错:CSRF token missing or incorrect.

解决方案: 1.在对应的模板中, 为每个POST的form添加一行代码:{% csrf_token %}. 如下所示: <form action = "" method = "post"> {% csrf_token %} <table> {{ form.as_table }} </table> <input type = "submit" value = "Submit"> &

django rest framework csrf failed csrf token missing or incorrect

REST_FRAMEWORK = { 'DEFAULT_AUTHENTICATION_CLASSES': ('rest_framework.authentication.TokenAuthentication',)} or MIDDLEWARE_CLASSES = ( 'store.disable.DisableCSRF',) disable.py class DisableCSRF(object): def process_request(self, request):        seta

PHP编译安装时常见错误解决办法,php编译常见错误

PHP编译安装时常见错误解决办法,php编译常见错误 1.configure: error: xslt-config not found. Please reinstall the libxslt >= 1.1.0 distribution 解决方法: yum -y install libxslt-devel 2.configure: error: Could not find net-snmp-config binary. Please check your net-snmp installa