File tree Expand file tree Collapse file tree 4 files changed +13
-12
lines changed Expand file tree Collapse file tree 4 files changed +13
-12
lines changed Original file line number Diff line number Diff line change @@ -38,6 +38,7 @@ function sameOrigin(url) {
38
38
! ( / ^ ( \/ \/ | h t t p : | h t t p s : ) .* / . test ( url ) ) ;
39
39
}
40
40
41
+ window . drf = JSON . parse ( document . getElementById ( 'drf_csrf' ) . textContent ) ;
41
42
var csrftoken = window . drf . csrfToken ;
42
43
43
44
$ . ajaxSetup ( {
Original file line number Diff line number Diff line change @@ -244,11 +244,11 @@ <h4 class="modal-title" id="myModalLabel">{{ error_title }}</h4>
244
244
{% endif %}
245
245
246
246
{% block script %}
247
- < script >
248
- window . drf = {
249
- csrfHeaderName : "{{ csrf_header_name|default:'X-CSRFToken' }}" ,
250
- csrfToken : "{{ csrf_token }}"
251
- } ;
247
+ < script type =" application/json " id =" drf_csrf " >
248
+ {
249
+ " csrfHeaderName" : "{{ csrf_header_name|default:'X-CSRFToken' }}" ,
250
+ " csrfToken" : "{{ csrf_token }}"
251
+ }
252
252
</ script >
253
253
< script src ="{% static "rest_framework /js/jquery-3.5.1.min.js" %}"> </ script >
254
254
< script src ="{% static "rest_framework /js/ajax-form.js" %}"> </ script >
Original file line number Diff line number Diff line change @@ -287,11 +287,11 @@ <h1>{{ name }}</h1>
287
287
{% endif %}
288
288
289
289
{% block script %}
290
- < script >
291
- window . drf = {
292
- csrfHeaderName : "{{ csrf_header_name|default:'X-CSRFToken' }}" ,
293
- csrfToken : "{% if request %}{{ csrf_token }}{% endif %}"
294
- } ;
290
+ < script type =" application/json " id =" drf_csrf " >
291
+ {
292
+ " csrfHeaderName" : "{{ csrf_header_name|default:'X-CSRFToken' }}" ,
293
+ " csrfToken" : "{% if request %}{{ csrf_token }}{% endif %}"
294
+ }
295
295
</ script >
296
296
< script src ="{% static "rest_framework /js/jquery-3.5.1.min.js" %}"> </ script >
297
297
< script src ="{% static "rest_framework /js/ajax-form.js" %}"> </ script >
Original file line number Diff line number Diff line change 6
6
def test_base_template_with_context ():
7
7
context = {'request' : True , 'csrf_token' : 'TOKEN' }
8
8
result = render ({}, 'rest_framework/base.html' , context = context )
9
- assert re .search (r'\bcsrfToken : "TOKEN"' , result .content .decode ())
9
+ assert re .search (r'"csrfToken" : "TOKEN"' , result .content .decode ())
10
10
11
11
12
12
def test_base_template_with_no_context ():
13
13
# base.html should be renderable with no context,
14
14
# so it can be easily extended.
15
15
result = render ({}, 'rest_framework/base.html' )
16
16
# note that this response will not include a valid CSRF token
17
- assert re .search (r'\bcsrfToken : ""' , result .content .decode ())
17
+ assert re .search (r'"csrfToken" : ""' , result .content .decode ())
You can’t perform that action at this time.
0 commit comments