I'm using Polymer 2.0 web components on my Django Project. I needed to make a POST request to my views.py but I'm getting a 403 Error (Forbidden) because my CSRF token was missing or incorrect.
Expected outcome
I should be able to see the body of my request in my views.py
Here's a sample of my views.py for the /delete_credits_submission/ url
"""Note that my request.POST or request.GET should contain this object:
{'pk': 4}
"""
def delete_credits_submission(request): print request.GET return HttpResponse('Success!', status=200)
Instead I'm getting this error:
Forbidden (CSRF token missing or incorrect.): /delete_credits_submission/
Usually, when I'm using the Django templates I can easily fix this problem using {% csrf_token %} but that's not the case here.
Description
I'm using Polymer 2.0 web components on my Django Project. I needed to make a POST request to my views.py but I'm getting a 403 Error (Forbidden) because my CSRF token was missing or incorrect.
Expected outcome
I should be able to see the body of my request in my views.py
Actual outcome
A CSRF error occurs.
Here's a sample code of my custom-element:
` <iron-ajax id="ironAjax" auto=[[auto]] url="/read_credit_submissions/" handle-as="json" last-response="{{response}}">
`
Here's a sample of my views.py for the
/delete_credits_submission/
url"""Note that my request.POST or request.GET should contain this object: {'pk': 4} """
def delete_credits_submission(request): print request.GET return HttpResponse('Success!', status=200)
Instead I'm getting this error:
Forbidden (CSRF token missing or incorrect.): /delete_credits_submission/
Usually, when I'm using the Django templates I can easily fix this problem using
{% csrf_token %}
but that's not the case here.