1
2# Error: forbidden (csrf cookie not set.)
3
4# ------------------------- SOLUTIONS ----------------------------- #
5
6 1º - In your views.py file:
7
8 def funtion(request):
9 var = request.POST['name_from_element'] #instead of GET
10 ...
11
12
13 2º - In your HTML:
14
15 <form action="something" method="post"> # use post
16
17 {% csrf_token %} # ativate this token
18
19 <label> Write a number: </label>
20 <input type="number" name="num" /><br />
21 <br />
22 <input type="submit" /> <br />
23</form>
24
25
26
27# OR
28
29
30
31 1º - In your views.py file, import:
32
33 from django.views.decorators.csrf import csrf_exempt
34
35
36
37 2º - Add the decorator to the function that is called:
38
39 @csrf_exempt
40 def funtion(request):
41 ...
42