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
- Template tag - list punctuation for a list of items by shapiromatron 9 months ago
- JSONRequestMiddleware adds a .json() method to your HttpRequests by cdcarter 9 months, 1 week ago
- Serializer factory with Django Rest Framework by julio 1 year, 3 months ago
- Image compression before saving the new model / work with JPG, PNG by Schleidens 1 year, 4 months ago
- Help text hyperlinks by sa2812 1 year, 5 months ago
Comments
Please login first before commenting.