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

posted @ 2021-06-03 18:14  船长博客  阅读(728)  评论(0编辑  收藏  举报
永远相信美好的事情即将发生!