24

Is there any way to get csrftoken in View straightly?

I want to get the current csrftoken in view but will change sometimes so get it from Cookies is not a good idea.

Is there any way to do that?

Thanks!

Gary
  • 1,199
  • 1
  • 9
  • 23

1 Answers1

43

I believe you're looking for this:

django.middleware.csrf.get_token(request)

or

{% csrf_token %}

Reference: How can I embed django csrf token straight into HTML?

Community
  • 1
  • 1
James111
  • 15,378
  • 15
  • 78
  • 121