[Django]-How import and use csrf token in django 1.11?

6👍

In Django 1.8 the template context processor was moved to django.template.context_processors.csrf, so the import would be:

from django.template.context_processors import csrf

However, you don’t need to import it at all. Stop using render_to_response, it’s obsolete. Use the render shortcut instead.

from django.shortcuts import render

return render(request, 'login.html', args)

When you use the render shortcut, then you don’t need to worry about the csrf token in the view, and you can remove this line.

args.update(csrf(request))

Leave a comment