In your approach, where you add a class to denote the active nav element to the element itself, you can add the name of the active nav element into the context from your view. Then, use some javascript to add the current
class to the appropriate element.
For example, if you have the following nav elements:
<a id="home" href="#">Home</a>
<a id="about" href="#">About</a>
In your view, add a context variable current
to denote the id of the current nav element by id:
return render_to_response('template.html',
{'current': 'home'})
Then in javascript (jQuery shown here):
$("#{{ current }}").addClass('current')
This will be evaluated as:
$("#home").addClass('current')
Which will in turn apply your #current CSS to the home element.
Another approach is to add a class to the body
tag which identifies the currently active nav menu. Then in your css, you define styles for each body class which highlight the appropriate nav item. Then, your template inserts the current
variable directly into the body class list, and there is no need for javascript.