Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added support for custom CSRF cookie names #4049

Merged
merged 1 commit into from
Apr 26, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 3 additions & 1 deletion rest_framework/renderers.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from collections import OrderedDict

from django import forms
from django.conf import settings
from django.core.exceptions import ImproperlyConfigured
from django.core.paginator import Page
from django.http.multipartparser import parse_header
Expand Down Expand Up @@ -657,7 +658,8 @@ def get_context(self, data, accepted_media_type, renderer_context):

'display_edit_forms': bool(response.status_code != 403),

'api_settings': api_settings
'api_settings': api_settings,
'csrf_cookie_name': settings.CSRF_COOKIE_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 @@ -33,7 +33,7 @@ function sameOrigin(url) {
!(/^(\/\/|http:|https:).*/.test(url));
}

var csrftoken = getCookie('csrftoken');
var csrftoken = getCookie(window.drf.csrfCookieName);

$.ajaxSetup({
beforeSend: function(xhr, settings) {
Expand Down
5 changes: 5 additions & 0 deletions rest_framework/templates/rest_framework/admin.html
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,11 @@ <h4 class="modal-title" id="myModalLabel">{{ error_title }}</h4>
{% if filter_form %}{{ filter_form }}{% endif %}

{% block script %}
<script>
window.drf = {
csrfCookieName: "{{ csrf_cookie_name|default:'csrftoken' }}"
};
</script>
<script src="{% static "rest_framework/js/jquery-1.11.3.min.js" %}"></script>
<script src="{% static "rest_framework/js/ajax-form.js" %}"></script>
<script src="{% static "rest_framework/js/csrf.js" %}"></script>
Expand Down
5 changes: 5 additions & 0 deletions rest_framework/templates/rest_framework/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,11 @@ <h1>{{ name }}</h1>
</div><!-- ./wrapper -->

{% block script %}
<script>
window.drf = {
csrfCookieName: "{{ csrf_cookie_name|default:'csrftoken' }}"
};
</script>
<script src="{% static "rest_framework/js/jquery-1.11.3.min.js" %}"></script>
<script src="{% static "rest_framework/js/ajax-form.js" %}"></script>
<script src="{% static "rest_framework/js/csrf.js" %}"></script>
Expand Down