Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Django CSRF Error: Only on local runserver

The same code from the repo works fine out in the wild. But on my local environment, I'm getting CSRF errors on form submits.

Django 1.11.13, Python 2.7

It's very hard to debug, because there's not really any breakpoint. the error occurs way before the view.

The CSRF token is in the form {% csrf_token %}, the hidden field is there, the cookie is there.

I've tried creating a new virtual environment, wiping the database, different browsers. What else?

like image 933
Rob L Avatar asked Aug 03 '18 21:08

Rob L


Video Answer


1 Answers

Well, I feel stupid. This must've occurred when we upgraded all our Django apps to v1.11 or v2.0. Somehow I got a SESSION_COOKIE_DOMAIN key in my local settings that reflected the domain of our staging environment. Live and learn.

like image 165
Rob L Avatar answered Sep 30 '22 17:09

Rob L