diff --git a/rest_framework/renderers.py b/rest_framework/renderers.py index 68af417da..53bbb1390 100644 --- a/rest_framework/renderers.py +++ b/rest_framework/renderers.py @@ -12,6 +12,7 @@ import json 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 @@ -657,7 +658,8 @@ class BrowsableAPIRenderer(BaseRenderer): '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 diff --git a/rest_framework/static/rest_framework/js/csrf.js b/rest_framework/static/rest_framework/js/csrf.js index 4e8da0de5..73d1ef67d 100644 --- a/rest_framework/static/rest_framework/js/csrf.js +++ b/rest_framework/static/rest_framework/js/csrf.js @@ -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) { diff --git a/rest_framework/templates/rest_framework/admin.html b/rest_framework/templates/rest_framework/admin.html index a86adbc60..a21ea57be 100644 --- a/rest_framework/templates/rest_framework/admin.html +++ b/rest_framework/templates/rest_framework/admin.html @@ -230,6 +230,11 @@ {% if filter_form %}{{ filter_form }}{% endif %} {% block script %} + diff --git a/rest_framework/templates/rest_framework/base.html b/rest_framework/templates/rest_framework/base.html index eccadc3cc..21431b70c 100644 --- a/rest_framework/templates/rest_framework/base.html +++ b/rest_framework/templates/rest_framework/base.html @@ -258,6 +258,11 @@ {% block script %} +