Skip to content
This repository was archived by the owner on May 5, 2023. It is now read-only.

Commit 764c246

Browse files
committed
feat: support cross-origin
1 parent 891efc3 commit 764c246

File tree

2 files changed

+34
-0
lines changed

2 files changed

+34
-0
lines changed

covid19/settings.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
'django.contrib.messages',
3939
'django.contrib.staticfiles',
4040

41+
'corsheaders',
4142
'django_crontab',
4243
'rest_framework',
4344
'django_filters',
@@ -47,6 +48,7 @@
4748
MIDDLEWARE = [
4849
'django.middleware.security.SecurityMiddleware',
4950
'django.contrib.sessions.middleware.SessionMiddleware',
51+
'corsheaders.middleware.CorsMiddleware',
5052
'django.middleware.common.CommonMiddleware',
5153
'django.middleware.csrf.CsrfViewMiddleware',
5254
'django.contrib.auth.middleware.AuthenticationMiddleware',
@@ -145,6 +147,37 @@
145147
}
146148
}
147149

150+
#跨域增加忽略
151+
CORS_ALLOW_CREDENTIALS = True
152+
CORS_ORIGIN_ALLOW_ALL = True
153+
CORS_ORIGIN_WHITELIST = (
154+
'*'
155+
)
156+
157+
CORS_ALLOW_METHODS = (
158+
'DELETE',
159+
'GET',
160+
'OPTIONS',
161+
'PATCH',
162+
'POST',
163+
'PUT',
164+
'VIEW',
165+
)
166+
167+
CORS_ALLOW_HEADERS = (
168+
'XMLHttpRequest',
169+
'X_FILENAME',
170+
'accept-encoding',
171+
'authorization',
172+
'content-type',
173+
'dnt',
174+
'origin',
175+
'user-agent',
176+
'x-csrftoken',
177+
'x-requested-with',
178+
'Pragma',
179+
)
180+
148181
CRONTAB_LOCK_JOBS = True
149182

150183
# 静态文件目录

requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ constantly==15.1.0
77
cryptography==2.9
88
cssselect==1.1.0
99
Django==2.2.12
10+
django-cors-headers==3.2.1
1011
django-crontab==0.7.1
1112
django-filter==2.2.0
1213
django-mysql==3.4.0

0 commit comments

Comments
 (0)