Forums

Can't import csrf module from within flask_wtf

Hi there,

I use flask_wtf to help do form validation. For some reason, when I run the init file on my web app I get the following response:

Traceback (most recent call last):
File "/home/...../__init__.py", line 9, in <module>
from flask_wtf.csrf import CsrfProtect
ImportError: No module named csrf
>>>

Can't quite work out why. Any ideas?? PS I have already tried importing flask_wtf in the bash console and this doesn't make any difference. PPS I don't encounter this issue when running on my own local host with flask_wtf installed.

Just for fun I thought I'd try the solution posed for the missing Cairo module https://www.pythonanywhere.com/forums/topic/1297/ This is the resulting error message:

Traceback (most recent call last):
File "/home/.../__init__.py", line 10, in <module>
flask_wtf.use("agg")
AttributeError: 'module' object has no attribute 'use'
>>>

I think it's because our default version of flask-wtf is a little out of date. You can upgrade it with:

pip install --user --upgrade flask-wtf

Or look into using a virtualenv (instructions refer to django, but you should be able to adapt them to flask...)

Hi Harry,

Thanks for that, it works a charm with the upgrade : )

thank you Harry, you save my night. the problem was update.