0

I have such a function(view)

def index(request):
    return render_to_response('index.html', context_instance=RequestContext(request))

and want to write just

return render_to_response('index.html')

Also I want to pass additional variables to view

return render_to_response('cart.html', {'key': value})

The main reason I need RequestContext is that I have context processor function that sets additional variables for me. How can I achieve that or is there different approach for doing such a thing?

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
Most Wanted
  • 6,254
  • 5
  • 53
  • 70

1 Answers1

0

You can use the render shortcut:

return render(request, 'cart.html', {'key': value})

You always need to pass the request, though: that's why it's called a RequestContext.

Daniel Roseman
  • 588,541
  • 66
  • 880
  • 895
  • Indeed, see https://docs.djangoproject.com/en/1.7/topics/http/shortcuts/#django.shortcuts.render – Mause Oct 30 '14 at 14:25