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