How can I get the csrftoken token in the view directly? [duplicate]
Asked Answered
K

2

27

Is there any way to get the csrftoken in my view directly?

Kristalkristan answered 1/4, 2016 at 3:28 Comment(0)
I
46

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?

Inoculate answered 1/4, 2016 at 3:33 Comment(1)
In form you must add '<input type="hidden" name="csrfmiddlewaretoken" value="' + get_token(request) + '"/>'Osteal
S
-2

tk = csrf(request).get("csrf_token")

Steenbok answered 23/4 at 6:43 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.