Search code examples
pythondjangotemplateshttprequestdjango-context

Default RequestContext in Django


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?


Solution

  • 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.