@register.assignment_tag(takes_context=True)
def get_back_button(context):
 request = context.get('request', None)
 if (not request):
  raise Exception('Cannot get request from context')
 referrer = request.META.get('HTTP_REFERER', None)
 if (not referrer):
  return None
 try:
  url = parse.urlparse(referrer)
 except (ValueError, TypeError):
  return None
 if (request.get_host() != url.netloc):
  try:
   Site.objects.get(domain=url.netloc)
  except Site.DoesNotExist:
   return None
 try:
  match = resolve(url.path)
 except Resolver404:
  return None
 titles = {'search:search': _('Back to search results')}
 title = titles.get(match.view_name, None)
 if (title is None):
  return None
 return {'url': referrer, 'title': six.text_type(title), 'match': match}

@ register . assignment_tag ( takes_context = True ) def get_back_button ( context ) : request = context . get ( 'request' , None ) if ( not request ) : raise Exception ( 'Cannot get request from context' ) referrer = request . META . get ( 'HTTP_REFERER' , None ) if ( not referrer ) : return None try : url = parse . urlparse ( referrer ) except ( ValueError , TypeError ) : return None if ( request . get_host ( ) != url . netloc ) : try : Site . objects . get ( domain = url . netloc ) except Site . DoesNotExist : return None try : match = resolve ( url . path ) except Resolver404 : return None titles = { 'search:search' : _ ( 'Back to search results' ) } title = titles . get ( match . view_name , None ) if ( title is None ) : return None return { 'url' : referrer , 'title' : six . text_type ( title ) , 'match' : match }
show back button .