Search code examples
pythondjangocsrfdjango-csrfcsrf-token

How can I embed django csrf token straight into HTML?


Is there a way to insert the the csrf token directly from within the Python files I'm editing? The token is different for each session, so storing it in the DB is not very useful. Is there a way to dynamically load the token within the view?


Solution

  • Call django.middleware.csrf.get_token(request) to get the CSRF token.