Login

location context_processor

Author:
gsf0
Posted:
August 14, 2009
Language:
Python
Version:
1.1
Tags:
url path location nav
Score:
1 (after 1 ratings)

A simple context_processor to include location info. Useful for permalinks, site name references, and navigation bars. For example:

{% if location.path|match:"/$" %} class="current"{% endif %}

See also my match filter.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
from django.contrib.sites.models import Site

def location(request):
    location = {}

    current_site = Site.objects.get_current()
    location['site'] = current_site
    
    script_name = request.META['SCRIPT_NAME']
    location['script_name'] = script_name
    
    path = request.META['PATH_INFO']
    location['path'] = path
    
    url = 'http://%s%s%s' % (current_site, script_name, path)
    location['url'] = url
    
    return {'location': location}

More like this

  1. match filter by gsf0 5 years, 7 months ago
  2. Simple Mobile Support by bahoo 4 years, 5 months ago
  3. Google Geocode Lookup by tonyskyday 7 years, 9 months ago
  4. Management command which helps to find temlate files by skyjur 4 years, 2 months ago
  5. Chain multiple querysets into one by mattdw 6 years, 5 months ago

Comments

Please login first before commenting.