Why on earth do I have to pass RequestContext in all of my responses? Why on earth do I have to pass RequestContext in all of my responses? django django

Why on earth do I have to pass RequestContext in all of my responses?


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_templatedef 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}     


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.