[Answered ]-In Django, how do I generate the CSRF input element while in a view?

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']
👤iMom0

Leave a comment