首先,什麼是跨域?協議、域名、端口任一不同即爲跨域。
django解決跨域問題。
首先安裝django-cors-headers
然後在django的setting中添加相應的配置
INSTALLED_APPS = [
...
'corsheaders',
...
]
MIDDLEWARE = [
...
# 注意兩個的順序
'corsheaders.middleware.CorsMiddleware', #新添
'django.middleware.common.CommonMiddleware', #默認
...
]
CORS_ALLOW_CREDENTIALS = True
CORS_ORIGIN_ALLOW_ALL = True
CORS_ALLOW_HEADERS = (' * ')
然後就可以解決跨域問題了。