1<form action="{% url "submit-form-url-name" %}" method="post" accept-charset="utf-8">
2 {% csrf_token %}
3 {{ form.field1 }}
4 {{ form.field2 }}
5 ...
6</form>
1function getCookie(name) {
2 let cookieValue = null;
3 if (document.cookie && document.cookie !== '') {
4 const cookies = document.cookie.split(';');
5 for (let i = 0; i < cookies.length; i++) {
6 const cookie = cookies[i].trim();
7 // Does this cookie string begin with the name we want?
8 if (cookie.substring(0, name.length + 1) === (name + '=')) {
9 cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
10 break;
11 }
12 }
13 }
14 return cookieValue;
15}
16const csrftoken = getCookie('csrftoken');
17