Django报错403 Forbidden. CSRF token missing or incorrect的解决办法
在JS中,使用post方法提交数据到后台,出现错误:
Forbidden (CSRF token missing or incorrect.):.........;
解决办法:
在页面导入JS的位置,补上以下代码即可:
<script>
$.ajaxSetup({
data:{csrfmiddlewaretoken:'{{ csrf_token }}'}
});
<script>
原文链接:https://blog.csdn.net/weixin_48154829/article/details/108006126
mysqlclient 1.4.0 or newer is required; you have %s.' % Database.__version__
https://www.cnblogs.com/qianzf/p/15684268.html
import pymysql pymysql.version_info = (1, 4, 13, "final", 0) pymysql.install_as_MySQLdb() # 使用pymysql代替mysqldb连接数据库
跨域
django跨域问题
https://blog.csdn.net/weixin_42322206/article/details/117171965?spm=1001.2101.3001.6661.1&utm_medium=distribute.pc_relevant_t0.none-task-blog-2%7Edefault%7ECTRLIST%7ERate-1-117171965-blog-84677213.pc_relevant_3mothn_strategy_recovery&depth_1-utm_source=distribute.pc_relevant_t0.none-task-blog-2%7Edefault%7ECTRLIST%7ERate-1-117171965-blog-84677213.pc_relevant_3mothn_strategy_recovery&utm_relevant_index=1
from django.utils.deprecation import MiddlewareMixin
from django.http import HttpResponse
class LoginToken(MiddlewareMixin):
def process_response(self,request,response):
# 添加响应头,允许跨域
response['Access-Control-Allow-Origin'] = "*"
response['Access-Control-Allow-Headers'] = "*"
response['Access-Control-Expose-Headers'] = "*"
response['Access-Control-Allow-Methods'] = "*"
response['Access-Control-Allow-Credentials']="true"
# 允许X-frame
response['X-Frame-Options'] = 'ALLOWALL'
return response
Django —— 中跨域配置 & axios
https://blog.csdn.net/jsxingmang/article/details/112060465
vue跨域配制(第一种方法)
在config文件夹下的index.js中配制
proxyTable: {
'/api': { //使用"/api"来代替"http://f.apiplus.c"
target: 'http://127.0.0.1:8000/', //源地址
changeOrigin: true, //改变源
pathRewrite: {
'^/api': '' //路径重写
}
}
},
promise.then返回结果几种情况
https://blog.csdn.net/m0_60909419/article/details/124110062
标签:Control,Access,relevant,跨域,几种,blog,promise,response From: https://www.cnblogs.com/hongdoudou/p/16777953.html