Guest User

Untitled

a guest
Nov 24th, 2017
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.82 KB | None | 0 0
  1. {detail: "CSRF Failed: CSRF token missing or incorrect."}
  2.  
  3. <div id="create_root"></div>
  4. {% render_bundle 'main_create_assessment' 'js' %}
  5. {% csrf_token %}
  6.  
  7. function getCookie(name) {
  8. if (!document.cookie) {
  9. return null;
  10. }
  11. const token = document.cookie.split(';')
  12. .map(c => c.trim())
  13. .filter(c => c.startsWith(name + '='));
  14.  
  15. if (token.length === 0) {
  16. return null;
  17. }
  18. return decodeURIComponent(token[0].split('=')[1]);
  19. }
  20.  
  21. const csrftoken = getCookie('csrftoken')
  22. console.log(csrftoken)
  23.  
  24. fetch(url, {
  25. credentials: 'include',
  26. method: 'POST',
  27. mode: 'same-origin',
  28. headers: {
  29. 'Accept': 'application/json',
  30. 'Content-Type': 'application/json',
  31. 'X-CSRFToken': csrftoken
  32. },
  33. body: JSON.stringify({
  34. title: this.state.title
  35. })
  36. })
  37. }
Add Comment
Please, Sign In to add comment