标签:setting 修改 ati ase wmi serve messages ted XML
一.修改settings文件
ALLOWED_HOSTS = [‘*‘]
INSTALLED_APPS = [ ‘corsheaders‘ ] #加入该app
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
标签:setting 修改 ati ase wmi serve messages ted XML
原文地址:https://www.cnblogs.com/sea-stream/p/9529022.html