七、跨域问题的解决

安装模块

pip3.8 install django-cors-headers -i https://pypi.tuna.tsinghua.edu.cn/simple/

注册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'
)