码迷,mamicode.com
首页 > 其他好文 > 详细

django中配置允许跨域请求

时间:2018-10-08 10:23:19      阅读:477      评论:0      收藏:0      [点我收藏+]

标签:list   文档   忽略   patch   get   ott   requested   methods   post   

对于django

安装django-cors-headers,详情请看官方文档

pip install django-cors-headers

  

配置settings.py文件

a.在INSTALLED_APPS里添加“corsheaders”

INSTALLED_APPS = [
    ...
    ‘corsheaders‘,
    ...
 ] 

  

b.在MIDDLEWARE_CLASSES添加 ‘corsheaders.middleware.CorsMiddleware’, ‘django.middleware.common.CommonMiddleware’

MIDDLEWARE_CLASSES = (
    ...
    ‘corsheaders.middleware.CorsMiddleware‘,
    ‘django.middleware.common.CommonMiddleware‘, 
    ...
)

  

c.在sitting.py底部添加

#跨域增加忽略
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‘,
)

  

 

django中配置允许跨域请求

标签:list   文档   忽略   patch   get   ott   requested   methods   post   

原文地址:https://www.cnblogs.com/randomlee/p/9752705.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!