django import csrf_exempt code example

Example 1: csrf_exempt

#first you need to import this
from django.views.decorators.csrf import csrf_exempt

#now use @csrf_exempt dacorator as follows

@csrf_exempt
def exampleview(request):
	pass
	#now this view will not require csrf_token to handle post requests

Example 2: import csrf_exempt django

from django.views.decorators.csrf import csrf_exemp

Example 3: Django Rendering Forms Manually and using csfr token

{% csrf_token %} {{ form.field1 }} {{ form.field2 }} ...

Tags:

Misc Example