Forbidden (CSRF cookie not set.) in django rest framework request code example
Example: django forbidden (csrf cookie not set.)
1º - In your views.py file:
def funtion(request):
var = request.POST['name_from_element']
...
2º - In your HTML:
<form action="something" method="post">
{% csrf_token %}
<label> Write a number: </label>
<input type="number" name="num" /><br />
<br />
<input type="submit" /> <br />
</form>
1º - In your views.py file, import:
from django.views.decorators.csrf import csrf_exempt
2º - Add the decorator to the function that is called:
@csrf_exempt
def funtion(request):
...