Skip to content

Commit 45df744

Browse files
cbergmillerjkimbo
authored andcommitted
Read csrftoken from DOM if no cookie is set (#826)
1 parent 3d01acf commit 45df744

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

graphene_django/static/graphene_django/graphiql.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,11 @@
33
// Parse the cookie value for a CSRF token
44
var csrftoken;
55
var cookies = ('; ' + document.cookie).split('; csrftoken=');
6-
if (cookies.length == 2)
6+
if (cookies.length == 2) {
77
csrftoken = cookies.pop().split(';').shift();
8+
} else {
9+
csrftoken = document.querySelector("[name=csrfmiddlewaretoken]").value;
10+
}
811

912
// Collect the URL parameters
1013
var parameters = {};

graphene_django/templates/graphene/graphiql.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
crossorigin="anonymous"></script>
3232
</head>
3333
<body>
34+
{% csrf_token %}
3435
<script src="{% static 'graphene_django/graphiql.js' %}"></script>
3536
</body>
3637
</html>

0 commit comments

Comments
 (0)