Django view shortcuts: render_to_response vs. render

If you’re using Django 1.3+, and find your code littered with

from django.shortcuts import render_to_response

def my_view(request):
  return render_to_response('my_template.html', my_data,

you can replace that with a call to the render() shortcut, introduced in Django 1.3:

from django.shortcuts import render

def my_view(request):
  return render(request, 'my_template.html', my_data)

You should generally prefer render() over render_to_response() – with render_to_response(), if you leave off the context_instance param, Django won’t invoke any of the default template context processors.

See the docs for more details.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s