django允许跨域请求配置

下载corsheader

pip install django-cors-headers

修改setting.py中配置

在INSTALLED_APPS中增加corsheaders

 1 INSTALLED_APPS = [
 2     'django.contrib.admin',
 3     'django.contrib.auth',
 4     'django.contrib.contenttypes',
 5     'django.contrib.sessions',
 6     'django.contrib.messages',
 7     'django.contrib.staticfiles',
 8     
 9     'corsheaders',  #就这里
10 ]
11 
12 MIDDLEWARE_CLASSES = [
13     'django.middleware.security.SecurityMiddleware',
14     'django.contrib.sessions.middleware.SessionMiddleware',
15     
16     'corsheaders.middleware.CorsMiddleware', #就这里
17     
18     'django.middleware.common.CommonMiddleware',
19     'django.middleware.csrf.CsrfViewMiddleware',
20     'django.contrib.auth.middleware.AuthenticationMiddleware',
21     'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
22     'django.contrib.messages.middleware.MessageMiddleware',
23     'django.middleware.clickjacking.XFrameOptionsMiddleware',
24 ]

setting 里再进行这样的配置

 

CORS_ORIGIN_ALLOW_ALL = True

 

posted @ 2018-11-15 09:54  lvye001  阅读(314)  评论(0编辑  收藏  举报