A neat little render_to_response trick
If you’ve used Django long enough, you will have noticed that render_to_response uses Context rather than RequestContext as the context instance. This is just no fun if you want to use things like auth, MEDIA_URL, etc in your templates. You could just add context_instance=RequestContext(request) to every render_to_response call, or you can use this little code snippet. Not only does it set the default context instance to RequestContext, but it’s a little less typing. In my projects, I put this in Commons.utils.
from django.template import RequestContext from django.shortcuts import render_to_response def render(request, *kargs, **kwargs): kwargs["context_instance"] = RequestContext(request) return render_to_response(*kargs, **kwargs)
Use it just as you would render_to_response, with the exception of setting context_instance. Enjoy!