我目前正在运行一个包含flask-wtf version 0.14.2
和wtforms version 2.21
的conda环境,在解决这个ImportError: cannot import name 'url_encode' from 'werkzeug'
问题时遇到了麻烦
下面的代码是完整的回溯。
Traceback (most recent call last):
File "run.py", line 1, in <module>
from flaskblog import app
File "/Users/justinding/Desktop/test/test_wesite/flaskblog/__init__.py", line 10, in <module>
from flaskblog import routes
File "/Users/justinding/Desktop/test/test_wesite/flaskblog/routes.py", line 4, in <module>
from flaskblog.forms import RegistrationForm,LoginForm
File "/Users/justinding/Desktop/test/test_wesite/flaskblog/forms.py", line 1, in <module>
from flask_wtf import FlaskForm
File "/opt/anaconda3/envs/smartbox/lib/python3.7/site-packages/flask_wtf/__init__.py", line 17, in <module>
from .recaptcha import *
File "/opt/anaconda3/envs/smartbox/lib/python3.7/site-packages/flask_wtf/recaptcha/__init__.py", line 2, in <module>
from .fields import *
File "/opt/anaconda3/envs/smartbox/lib/python3.7/site-packages/flask_wtf/recaptcha/fields.py", line 3, in <module>
from . import widgets
File "/opt/anaconda3/envs/smartbox/lib/python3.7/site-packages/flask_wtf/recaptcha/widgets.py", line 5, in <module>
from werkzeug import url_encode
ImportError: cannot import name 'url_encode' from 'werkzeug' (/opt/anaconda3/envs/smartbox/lib/python3.7/site-packages/werkzeug/__init__.py)
4条答案
按热度按时间ohfgkhjo1#
在需求文件中设置werkzeug==0.16.1可以修复它。问题出在1.0.0版本
2vuwiymt2#
我猜这个错误与werkzeug的新版本有关。在新werkzeug版本中,没有“url_encode”。所以尝试安装一个旧版本的werkzeug如下:“pip install werkzeug==0.16.0”mine已使用此解决方案修复
ymzxtsji3#
尝试从werkzeug.urls导入
aiazj4mn4#
使用Below语法
从werkzeug.urls导入url_encode