Read csrftoken from DOM if no cookie is set (#826)

This commit is contained in:
cbergmiller 2019-12-27 15:26:42 +01:00 committed by Jonathan Kim
parent 3d01acf169
commit 45df7445f4
2 changed files with 5 additions and 1 deletions

View File

@ -3,8 +3,11 @@
// Parse the cookie value for a CSRF token // Parse the cookie value for a CSRF token
var csrftoken; var csrftoken;
var cookies = ('; ' + document.cookie).split('; csrftoken='); var cookies = ('; ' + document.cookie).split('; csrftoken=');
if (cookies.length == 2) if (cookies.length == 2) {
csrftoken = cookies.pop().split(';').shift(); csrftoken = cookies.pop().split(';').shift();
} else {
csrftoken = document.querySelector("[name=csrfmiddlewaretoken]").value;
}
// Collect the URL parameters // Collect the URL parameters
var parameters = {}; var parameters = {};

View File

@ -31,6 +31,7 @@ add "&raw" to the end of the URL within a browser.
crossorigin="anonymous"></script> crossorigin="anonymous"></script>
</head> </head>
<body> <body>
{% csrf_token %}
<script src="{% static 'graphene_django/graphiql.js' %}"></script> <script src="{% static 'graphene_django/graphiql.js' %}"></script>
</body> </body>
</html> </html>