0%

Cross-Origin Resource Sharing

Cross-Origin Resource Sharing - 跨域问题

1
2
3
4
5
# 1
pip install Django-cors-headers

# 推荐
pip install djangorestframework markdown django-filter pillow django-guardian coreapi
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# 2
# Application definition
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'app01.apps.App01Config',
'rest_framework'
]


# 3
MIDDLEWARE = [
'corsheaers.middleware.CorsMiddleware' # be the first
....
]

# 4
CORS_ORIGIN_ALLOW_ALL = True