0

Hello I'm trying to do something like this

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

In django

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

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

But I only get this: POST / 403 FORBIDDEN

Jeroj82
  • 401
  • 3
  • 14
  • Possible duplicate of [Django csrf token + Angularjs](http://stackoverflow.com/questions/18156452/django-csrf-token-angularjs) – falsetru Nov 15 '15 at 11:57

1 Answers1

1

Add @api_view(['POST']) on the line before myView function:

@api_view(['POST'])
def myView(request):
    //so on
Tarun Dugar
  • 8,921
  • 8
  • 42
  • 79
  • Ok, It's works fine, but It's not what I want to. I need to have my html template. In template - button. When I'll click the button i need to send post from angulary to django, and in django call some method. – Jeroj82 Nov 15 '15 at 12:07