Skip to content

Instantly share code, notes, and snippets.

View jesskturner's full-sized avatar

Jessica Turner jesskturner

View GitHub Profile
@stephenemslie
stephenemslie / resolvermatch.py
Created February 3, 2011 12:35
Very simple but useful Django context processor to generate a ResolverMatch object from request.path and add this to the context. Handy in checking for active urls or namespaces.
"""
resolved_pattern Django context processor: insert the current url's ResolverMatch object into context.
Example use: Set class=active to a menu item, based on the namespace of the currently matched url.
<li {% if resolved.namespace == "home" %}class="active"{% endif %}> home </li>
or more specifically:
<li {% if resolved.view_name == "contact" %}class="active"{% endif %}> contact </li>