csrf exept django 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: how to send csrf middleware token in django ajax
{% csrf_token %}
<script>
const csrftoken = document.querySelector('[name=csrfmiddlewaretoken]').value;
</script>