django csrf token in javascript
<form action="{ % url "submit-form-url-name" %}" method="post" accept-charset="utf-8">
{ % csrf_token %}
{{ form.field1 }}
{{ form.field2 }}
...
</form>function getCookie(name) {
let cookieValue = null;
if (document.cookie && document.cookie !== '') {
const cookies = document.cookie.split(';');
for (let i = 0; i < cookies.length; i++) {
const cookie = cookies[i].trim();
// Does this cookie string begin with the name we want?
if (cookie.substring(0, name.length + 1) === (name + '=')) {
cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
break;
}
}
}
return cookieValue;
}
const csrftoken = getCookie('csrftoken');
Also in JavaScript:
- js get the week monday to friday date
- javascript clone array of objects
- linkedin api v2 get email address
- javjquery is emptyobject
- check data type in js
- java script hash
- javascript addeventlistener
- js oneline foreach
- js document onload
- class query css js all
- web scraping node js puppeteer
- merge 2 arrays jquery
- javascript algorithms
- javascript location.href
- jquery clone
- joudyhallo
- how to scroll to top of a page automatically using javascript
- using a variable in regex javascript with boundary marker
- loop through object javascript
- express router middleware
- express-jwt error algorithms should be set
- sort date array javascript
- unique values in array javascript
- array of array key value javascript