django-cors-headers not work

后端 未结 13 1408
情深已故
情深已故 2020-12-29 04:10

django-cors-headers not work

INSTALLED_APPS = (
    \'django.contrib.admin\',
    \'django.contrib.auth\',
    \'django.contrib.contenttypes\',
    \'django.         


        
13条回答
  •  失恋的感觉
    2020-12-29 04:24

    This worked for me:

    python -m pip install django-cors-headers
    
    MIDDLEWARE = [  
        ...
        'corsheaders.middleware.CorsMiddleware',
        'django.middleware.common.CommonMiddleware',
        ...
    ]
    
    INSTALLED_APPS = [
        ...
        'corsheaders',
        ...
    ]
    
    `ALLOWED_HOSTS = ['*']`
    
    `CORS_ORIGIN_ALLOW_ALL = True`
    

    Make sure to include: corsheaders.middleware.CorsMiddleware, as high as possible

    For reference: https://pypi.org/project/django-cors-headers/, https://docs.djangoproject.com/en/3.0/ref/settings/

提交回复
热议问题