          <ul class="dropdown-menu">
              <li><a href='{href}?next={next}'>Log out</a></li>
          </ul>
      </li>"""
      snippet = snippet.format(user=escape(user), href=logout_url, next=escape(request.path))
      return mark_safe(snippet)
  
  
  @register.simple_tag
  def add_query_param(request, key, val):
 
</s> remove     snippet = snippet.format(href=login_url, next=escape(request.path))
 </s> add     snippet = format_html(snippet, href=login_url, next=escape(request.path))
 </s> remove from django.utils.html import escape, smart_urlquote
 </s> add from django.utils.html import escape, format_html, smart_urlquote
    snippet = format_html(snippet, user=escape(user), href=logout_url, next=escape(request.path))

          <ul class="dropdown-menu">
              <li><a href='{href}?next={next}'>Log out</a></li>
          </ul>
      </li>"""
    snippet = format_html(snippet, user=escape(user), href=logout_url, next=escape(request.path))

      return mark_safe(snippet)
  
  
  @register.simple_tag
  def add_query_param(request, key, val):
keep keep keep keep replace keep keep keep keep keep
 Use format_html in tags that generate HTML 
rest_framework/templatetags/rest_framework.py