2👍
✅
Follow the doc, use the processor to generate the CSRF token:
from django.core.context_processors import csrf
def my_view(request):
# csrf(request) returns a dict like {'csrf_token': 'xxx'}
csrf_token = csrf(request)['csrf_token']
Source:stackexchange.com