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

前端 未结 11 730
隐瞒了意图╮
隐瞒了意图╮ 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:15

    i was using python 2.7 and due to some reasons i cannot change the python version to version 3 and it took me 3 hours to find a solution which is :

    response =  HttpResponse(json.dumps(result), content_type="application/json")
    response["Access-Control-Allow-Origin"] = '*'
    response["Access-Control-Allow-Methods"] = 'GET,PUT, OPTIONS'
    response["Access-Control-Max-Age"] = '1000'
    response["Access-Control-Allow-Headers"] = 'X-Requested-With, Content-Type'
    return response
    

提交回复
热议问题