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) {
3838 ! ( / ^ ( \/ \/ | h t t p : | h t t p s : ) .* / . test ( url ) ) ;
3939}
4040
41- var csrftoken = getCookie ( window . drf . csrfCookieName ) ;
41+ var csrftoken = window . drf . csrfToken ;
4242
4343$ . ajaxSetup ( {
4444 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>
247247 < script >
248248 window . drf = {
249249 csrfHeaderName : "{{ csrf_header_name|default:'X-CSRFToken' }}" ,
250- csrfCookieName : "{{ csrf_cookie_name|default:'csrftoken' }}"
250+ csrfToken : "{{ csrf_token }}"
251251 } ;
252252 </ script >
253253 < 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>
290290 < script >
291291 window . drf = {
292292 csrfHeaderName : "{{ csrf_header_name|default:'X-CSRFToken' }}" ,
293- csrfCookieName : "{{ csrf_cookie_name|default:'csrftoken' } }"
293+ csrfToken : "{% if request %}{{ csrf_token }}{% endif % }"
294294 } ;
295295 </ script >
296296 < 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+
13from django .shortcuts import render
24
35
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+
412def test_base_template_with_no_context ():
513 # base.html should be renderable with no context,
614 # 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