I want to highlight the current page in the navigation menu. Obviously I need to give the menu links a class like \'active\' when you are on their page. This is a classic pr
Your intention makes sense, you'll need RequestContext
most of the time and only rarely it can be safely omitted for performance reasons. The solution is simple, instead of render_to_response
use direct_to_template
shortcut:
from django.views.generic.simple import direct_to_template
def contact(request):
# snip ...
return direct_to_template(request, 'contact.html', { 'myvar' : myvar })
... or render_to
decorator from django-annoying:
from annoying.decorators import render_to
@render_to('template.html')
def foo(request):
bar = Bar.object.all()
return {'bar': bar}
For future reference, one can use django-tabs for doing what OP wanted.
You don't necessarily have to do anything to the markup of your navigation to give the current one a different style - there are declarative ways to do that using CSS.
See my answer here: Django: Is there a better way to bold the current page link for an example.