Forms with and without csrf tokens on single page

209 views Asked by At

I have a login form on every page that's a popup, and it requires the csrf token. I also have some form views that have a form that doesn't require the csrf token.

What I've found is that even if I have the {% csrf_token %} on the login form, if the view isn't wrapped with csrf_protect() it doesn't generate the token, so when the login form is submitted, it gets a csrf missing error. OTOH, if I do wrap it, then the other form on the page that doesn't need it complains about it missing though the login form works. One form submits to the current page form view, while the form submits to a separate form view.

Is it possible to get the csrf_token to generate even without the csrf_protect being used?

I saw the csrf_exempt function but it doesn't help when wrapping the view either. Is it possible to render two view functions or wrap it within the template? I'm just using a {% include login.html %}

Thanks

0

There are 0 answers