首页 > 其他分享 >关于前后端跨域问题的解决

关于前后端跨域问题的解决

时间:2023-02-26 17:35:31浏览次数:56  
标签:注册 corsheaders 跨域 前后 ALLOW CORS 解决

跨域问题的解决

安装模块

pip3.8 install django-cors-headers -i 

注册app

'corsheaders'

注册中间件

'corsheaders.middleware.CorsMiddleware',

添加配置文件

CORS_ORIGIN_ALLOW_ALL = True
# 请求方式
CORS_ALLOW_METHODS = (
	'DELETE',
	'GET',
	'OPTIONS',
	'PATCH',
	'POST',
	'PUT',
	'VIEW',
)
# 请求头
CORS_ALLOW_HEADERS = (
	'XMLHttpRequest',
	'X_FILENAME',
	'accept-encoding',
	'authorization',
	'content-type',
	'dnt',
	'origin',
	'user-agent',
	'x-csrftoken',
	'x-requested-with',
	'Pragma',
	'token'
)

出处:https://www.cnblogs.com/liuqingzheng/articles/17132395.html

标签:注册,corsheaders,跨域,前后,ALLOW,CORS,解决
From: https://www.cnblogs.com/wxlxl/p/17157130.html

相关文章