Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- {detail: "CSRF Failed: CSRF token missing or incorrect."}
- <div id="create_root"></div>
- {% render_bundle 'main_create_assessment' 'js' %}
- {% csrf_token %}
- function getCookie(name) {
- if (!document.cookie) {
- return null;
- }
- const token = document.cookie.split(';')
- .map(c => c.trim())
- .filter(c => c.startsWith(name + '='));
- if (token.length === 0) {
- return null;
- }
- return decodeURIComponent(token[0].split('=')[1]);
- }
- const csrftoken = getCookie('csrftoken')
- console.log(csrftoken)
- fetch(url, {
- credentials: 'include',
- method: 'POST',
- mode: 'same-origin',
- headers: {
- 'Accept': 'application/json',
- 'Content-Type': 'application/json',
- 'X-CSRFToken': csrftoken
- },
- body: JSON.stringify({
- title: this.state.title
- })
- })
- }
Add Comment
Please, Sign In to add comment