Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
0a48d21
fix a b0rked code example in the permissions section of api guide
wimglenn Aug 12, 2016
b508bc8
Merge pull request #4396 from wimglenn/docs_bugfix
jpadilla Aug 13, 2016
075a0bd
Fix template syntax error for `as_list_of_strings` (#4403)
jamesbeith Aug 15, 2016
785b206
Tweak doctsring. Closes #4404 [ci skip]
lovelydinosaur Aug 15, 2016
101fd29
Do not include uploads in request.POST (#4407)
lovelydinosaur Aug 15, 2016
e3f8d06
Include .action attribute on viewsets when generating schemas (#4408)
lovelydinosaur Aug 15, 2016
966330a
Replace utf8 character ' with its ascii counterpart, makes bdist_rpm.…
nevun Aug 17, 2016
b76984d
Allow custom CSRF_HEADER_NAME setting. (#4415)
lovelydinosaur Aug 18, 2016
382ea77
Improve debug error handling (#4416)
lovelydinosaur Aug 18, 2016
59ca61a
Add django-rest-framework-roles to third party packages in permission…
r1b Aug 19, 2016
e5b4498
Initial tests for API client
lovelydinosaur Aug 19, 2016
63342e8
Version 3.4.5 (#4421)
lovelydinosaur Aug 19, 2016
a335309
Add __str__ method to PKOnlyObject (#4423)
lovelydinosaur Aug 19, 2016
d540f02
Improve Create to show the original exception traceback (#3508)
orf Aug 19, 2016
c5e80e1
Merge branch 'master' into api-client
lovelydinosaur Aug 19, 2016
1a73c1c
Initial test cases for API client
lovelydinosaur Aug 19, 2016
e615f6d
Tests for API clients
lovelydinosaur Aug 22, 2016
341fa58
Support raw file uplaods with requests client / api client.
lovelydinosaur Aug 22, 2016
fe706eb
Tweak to tests for py3
lovelydinosaur Aug 22, 2016
b56e7d3
Upload and download support
lovelydinosaur Sep 9, 2016
b41ec30
Py3 compat
lovelydinosaur Sep 9, 2016
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Allow custom CSRF_HEADER_NAME setting. (#4415)
  • Loading branch information
lovelydinosaur authored Aug 18, 2016
commit b76984d222281e58e3105df0128141567b9a7697
9 changes: 8 additions & 1 deletion rest_framework/renderers.py
Original file line number Diff line number Diff line change
Expand Up @@ -645,6 +645,12 @@ def get_context(self, data, accepted_media_type, renderer_context):
else:
paginator = None

csrf_cookie_name = settings.CSRF_COOKIE_NAME
csrf_header_name = getattr(settings, 'CSRF_HEADER_NAME', 'HTTP_X_CSRFToken') # Fallback for Django 1.8
if csrf_header_name.startswith('HTTP_'):
csrf_header_name = csrf_header_name[5:]
csrf_header_name = csrf_header_name.replace('_', '-')

context = {
'content': self.get_content(renderer, data, accepted_media_type, renderer_context),
'view': view,
Expand Down Expand Up @@ -675,7 +681,8 @@ def get_context(self, data, accepted_media_type, renderer_context):
'display_edit_forms': bool(response.status_code != 403),

'api_settings': api_settings,
'csrf_cookie_name': settings.CSRF_COOKIE_NAME,
'csrf_cookie_name': csrf_cookie_name,
'csrf_header_name': csrf_header_name
}
return context

Expand Down
2 changes: 1 addition & 1 deletion rest_framework/static/rest_framework/js/csrf.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ $.ajaxSetup({
// Send the token to same-origin, relative URLs only.
// Send the token only if the method warrants CSRF protection
// Using the CSRFToken value acquired earlier
xhr.setRequestHeader("X-CSRFToken", csrftoken);
xhr.setRequestHeader(window.drf.csrfHeaderName, csrftoken);
}
}
});
1 change: 1 addition & 0 deletions rest_framework/templates/rest_framework/admin.html
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,7 @@ <h4 class="modal-title" id="myModalLabel">{{ error_title }}</h4>
{% block script %}
<script>
window.drf = {
csrfHeaderName: "{{ csrf_header_name|default:'X-CSRFToken' }}"
csrfCookieName: "{{ csrf_cookie_name|default:'csrftoken' }}"
};
</script>
Expand Down
1 change: 1 addition & 0 deletions rest_framework/templates/rest_framework/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,7 @@ <h1>{{ name }}</h1>
{% block script %}
<script>
window.drf = {
csrfHeaderName: "{{ csrf_header_name|default:'X-CSRFToken' }}"
csrfCookieName: "{{ csrf_cookie_name|default:'csrftoken' }}"
};
</script>
Expand Down