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
- Form field with fixed value by roam 4 days, 2 hours ago
- New Snippet! by Antoliny0919 1 week, 3 days ago
- Add Toggle Switch Widget to Django Forms by OgliariNatan 2 months, 4 weeks ago
- get_object_or_none by azwdevops 6 months, 3 weeks ago
- Mask sensitive data from logger by agusmakmun 8 months, 2 weeks ago
Comments
Please login first before commenting.