django中配置允许跨域请求

 

https://www.cnblogs.com/randomlee/p/9752705.html

 

pip install django-cors-headers==3.10.0
INSTALLED_APPS = [
    ...
    'corsheaders',
    ...
 ]
MIDDLEWARE_CLASSES = (
    ...
    'corsheaders.middleware.CorsMiddleware',
    'django.middleware.common.CommonMiddleware',
    ...
)
CORS_ALLOW_CREDENTIALS = True
CORS_ORIGIN_ALLOW_ALL = True
CORS_ORIGIN_WHITELIST = ()
 
CORS_ALLOW_METHODS = (
    'DELETE',
    'GET',
    'OPTIONS',
    'PATCH',
    'POST',
    'PUT',
    'VIEW',
)
 
CORS_ALLOW_HEADERS = (
    'accept',
    'accept-encoding',
    'authorization',
    'content-type',
    'dnt',
    'origin',
    'user-agent',
    'x-csrftoken',
    'x-requested-with',
)

 

posted @ 2022-02-15 16:50  CodeYaSuo  阅读(219)  评论(0编辑  收藏  举报