Why does Django's render() function need the "request" argument?

The render() shortcut renders templates with a request context. Template context processors take the request object and return a dictionary which is added to the context.

A common template context processor is the auth context processor, which takes the request object, and adds the logged-in user to the context.

If you don't need to render the template with a request context, you can use request=None.

def my_view(request):
    return render(None, "my_template.html", {'foo': 'bar'})

Tags:

Django