diff --git a/rest_framework/templates/rest_framework/admin.html b/rest_framework/templates/rest_framework/admin.html
index 7c6917e2d..a5edf529e 100644
--- a/rest_framework/templates/rest_framework/admin.html
+++ b/rest_framework/templates/rest_framework/admin.html
@@ -42,7 +42,7 @@
{% block userlinks %}
{% if user.is_authenticated %}
- {% optional_logout request user %}
+ {% optional_logout request user csrf_token %}
{% else %}
{% optional_login request %}
{% endif %}
diff --git a/rest_framework/templates/rest_framework/base.html b/rest_framework/templates/rest_framework/base.html
index 686dd831f..7f16482b7 100644
--- a/rest_framework/templates/rest_framework/base.html
+++ b/rest_framework/templates/rest_framework/base.html
@@ -46,7 +46,7 @@
{% block userlinks %}
{% if user.is_authenticated %}
- {% optional_logout request user %}
+ {% optional_logout request user csrf_token %}
{% else %}
{% optional_login request %}
{% endif %}
diff --git a/rest_framework/templatetags/rest_framework.py b/rest_framework/templatetags/rest_framework.py
index 53916d3f2..e01568cf2 100644
--- a/rest_framework/templatetags/rest_framework.py
+++ b/rest_framework/templatetags/rest_framework.py
@@ -119,7 +119,7 @@ def optional_docs_login(request):
@register.simple_tag
-def optional_logout(request, user):
+def optional_logout(request, user, csrf_token):
"""
Include a logout snippet if REST framework's logout view is in the URLconf.
"""
@@ -135,11 +135,16 @@ def optional_logout(request, user):
+
+ Log out
+
"""
- snippet = format_html(snippet, user=escape(user), href=logout_url, next=escape(request.path))
-
+ snippet = format_html(snippet, user=escape(user), href=logout_url,
+ next=escape(request.path), csrf_token=csrf_token)
return mark_safe(snippet)