django跨站问题 blocked by CORS policy: No 'Access-Control-Allow-Origin'
仅作为调试用,简单粗暴
ALLOWED_HOSTS=['*'] CORS_ORIGIN_ALLOW_ALL = True
或者:
1. pip install django-cors-headers 2. INSTALLED_APPS = [ ... 'corsheaders', ... ] 3. MIDDLEWARE = [ ... 'corsheaders.middleware.CorsMiddleware', ... ] 4. ALLOWED_HOSTS=['http://localhost:5000'] CORS_ORIGIN_ALLOW_ALL = False CORS_ORIGIN_WHITELIST = ( 'http://localhost:5000', )
来源:https://dzone.com/articles/how-to-fix-django-cors-error