@register.simple_tag
def optional_login(request):
 try:
  login_url = reverse(u'rest_framework:login')
 except NoReverseMatch:
  return u''
 snippet = u"<li><a href='{href}?next={next}'>Log in</a></li>"
 snippet = format_html(snippet, href=login_url, next=escape(request.path))
 return mark_safe(snippet)

@ register . simple_tag def optional_login ( request ) : try : login_url = reverse ( u'rest_framework:login' ) except NoReverseMatch : return u'' snippet = u"<li><a href='{href}?next={next}'>Log in</a></li>" snippet = format_html ( snippet , href = login_url , next = escape ( request . path ) ) return mark_safe ( snippet )
include a login snippet if rest frameworks login view is in the urlconf .