Flask-WTF CSRF token error when on Docker Flask-WTF CSRF token error when on Docker flask flask

Flask-WTF CSRF token error when on Docker


Chances are this is because you're using Docker Machine, and your SERVER_NAME is set to 192.168.99.100 (or whatever your default Docker Machine IP is).

I've noticed that most webkit based browsers don't set cookies for IP based domains, but they allow localhost.

One option you could do is:

  • Edit your /etc/hosts file by adding: 192.168.99.100 local.docker (replacing that IP with your Docker Machine IP address if it's different).

  • Change your SERVER_NAME to use local.docker.

If you want to see a full write up about this, I blogged about it a while back at https://nickjanetakis.com/blog/fix-missing-csrf-token-issues-with-flask.