Cannot import name 'TextField' from 'wtforms'
This page explains How to Fix ImportError: cannot import name 'TextField' from 'wtforms'
​WTForms is a flexible forms validation and rendering library for Python web development. It can work with whatever web framework and template engine you choose. It supports data validation, CSRF protection, internationalization (I18N).
WTForms TextField import Error

Error Text

1
from wtforms import TextField
2
>> ImportError: cannot import name 'TextField' from 'wtforms'
Copied!
The above error occurs when the TextField property is used with WTForms version 3.0 or above because the wtforms.TextField deprecated in favor of wtforms.StringField.
​

How to Fix

Solution 1 - Replace TextField type with StringField
Note: This solution works with WTForms 3.x and 2.x versions
1
from wtforms import StringField
2
// replace all TextField usages with StringField type
Copied!
Solution 2 - Use the latest stable 2.x version of WTForms
1
// Use 2.x version
2
pip install WTForms==2.3.3
Copied!
Using an older version provides a quick fix for your codebase but is not recommended in the long run.
​

Resources

Last modified 23d ago