Reputation: 993
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?
Upvotes: 46
Views: 47111
Reputation: 26312
Call django.middleware.csrf.get_token(request)
to get the CSRF token.
Upvotes: 57
Reputation: 87095
The way to use it, is to use it directly in the templates.
From the documentation,:
<form action="" method="post">
{% csrf_token %}
is all you have to include.
Upvotes: 53