diff --git a/rest_framework/templatetags/rest_framework.py b/rest_framework/templatetags/rest_framework.py
index 0069d9a5e..08acecef7 100644
--- a/rest_framework/templatetags/rest_framework.py
+++ b/rest_framework/templatetags/rest_framework.py
@@ -41,8 +41,9 @@ def optional_login(request):
except NoReverseMatch:
return ''
- snippet = "
Log in".format(href=login_url, next=escape(request.path))
- return snippet
+ snippet = "Log in"
+ snippet = snippet.format(href=login_url, next=escape(request.path))
+ return mark_safe(snippet)
@register.simple_tag
@@ -64,8 +65,8 @@ def optional_logout(request, user):
Log out
"""
-
- return snippet.format(user=user, href=logout_url, next=escape(request.path))
+ snippet = snippet.format(user=escape(user), href=logout_url, next=escape(request.path))
+ return mark_safe(snippet)
@register.simple_tag