Skip to content Skip to sidebar Skip to footer

How Import And Use Csrf Token In Django 1.11?

Pease help use csrf token in django 1.11 in view.py i use follow code: from django.shortcuts import render_to_response, redirect from django.contrib import auth from django.views.d

Solution 1:

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.shortcutsimport render

returnrender(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))

Post a Comment for "How Import And Use Csrf Token In Django 1.11?"