禁止从Angular发布到Django

时间:2015-11-15 11:54:00

标签: angularjs django

您好我试图做这样的事情

$http({
    url: '/',
    method: "POST",
    data: $.param('test=data'),
    headers: {
        'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'
    }
})

在django

#urls
url(r'^$', myView),

#views
def myView(request):
    if request.method == "POST":
        print "POST", request.POST
        return render(request, 'index.html')

但我只能得到这个:POST / 403 FORBIDDEN

1 个答案:

答案 0 :(得分:1)

在myView功能之前的行上添加@api_view(['POST'])

@api_view(['POST'])
def myView(request):
    //so on