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

django 接口编写的配置

时间:2018-08-24 13:21:24      阅读:271      评论:0      收藏:0      [点我收藏+]

标签:setting   修改   ati   ase   wmi   serve   messages   ted   XML   

一.修改settings文件

ALLOWED_HOSTS = [‘*‘]

 

INSTALLED_APPS = [ ‘corsheaders‘ ]    #加入该app

 

安装django-cors-headers:

pip install django-cors-headers

 

#注释掉跨域的中间件CsrfViewMiddleware,SessionMiddleware要在AuthenticationMiddleware前面,CorsMiddleware要在CommonMiddleware前面

MIDDLEWARE = [

‘django.middleware.security.SecurityMiddleware‘,

‘corsheaders.middleware.CorsMiddleware‘,

‘django.middleware.common.CommonMiddleware‘,

#‘django.middleware.csrf.CsrfViewMiddleware‘,

‘django.contrib.sessions.middleware.SessionMiddleware‘,

‘django.contrib.auth.middleware.AuthenticationMiddleware‘,

‘django.contrib.messages.middleware.MessageMiddleware‘,

‘django.middleware.clickjacking.XFrameOptionsMiddleware‘, ]

 

 

加入跨域配置:

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 = ( ‘XMLHttpRequest‘, ‘X_FILENAME‘, ‘accept-encoding‘, ‘authorization‘, ‘content-type‘, ‘dnt‘, ‘origin‘, ‘user-agent‘, ‘x-csrftoken‘, ‘x-requested-with‘, ‘Pragma‘, )

 

 

运行项目时,输入命令#Python manage.py runserver 192.168.1.111:8000,在本机的浏览器中输入http://192.168.1.111:8000

 

 

django 接口编写的配置

标签:setting   修改   ati   ase   wmi   serve   messages   ted   XML   

原文地址:https://www.cnblogs.com/sea-stream/p/9529022.html

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