Access-Control-Allow-Origin in Django app when accessed with Phonegap

前端 未结 3 2096
太阳男子
太阳男子 2020-12-13 02:04

I\'m developing a Phonegap app for my Django based app, but when trying to make Ajax calls I get this error:

XMLHttpRequest cannot load http://domain.herokua         


        
3条回答
  •  时光取名叫无心
    2020-12-13 02:44

    For single views you can manually add headers:

    @require_GET
    def api_getto(request):
        response = JsonResponse(
            # your stuff here
        )
        response["Access-Control-Allow-Origin"] = "*"
        response["Access-Control-Allow-Methods"] = "GET, OPTIONS"
        response["Access-Control-Max-Age"] = "1000"
        response["Access-Control-Allow-Headers"] = "X-Requested-With, Content-Type"
        return response
    

提交回复
热议问题