“No 'Access-Control-Allow-Origin' header is present on the requested resource” in django

前端 未结 11 725
隐瞒了意图╮
隐瞒了意图╮ 2020-12-02 16:44

I am newbie to django and using it as back end for an application that creates users. In front end the code for posting the user name is :

var xobj = new XM         


        
11条回答
  •  不知归路
    2020-12-02 17:35

    Add following line in middleware classes

    'corsheaders.middleware.CorsPostCsrfMiddleware'
    

    so overall implementation would be:

    INSTALLED_APPS = (
        ...
        'corsheaders',
        ...
    )
    
    MIDDLEWARE_CLASSES = (
        ...
        'corsheaders.middleware.CorsMiddleware',
        'django.middleware.common.CommonMiddleware',
        'corsheaders.middleware.CorsPostCsrfMiddleware'
    
        ...
    )
    
    CORS_ORIGIN_ALLOW_ALL = True   
    

    check documentaion below for more info

提交回复
热议问题