Python Flask flask-admin wtforms.validators AttributeError

Python Flask flask-admin wtforms.validators AttributeError

我正在阅读 Matt Copperwaite 的基于 Flask 的教程“学习 Flask 框架”,现在我陷入了以下错误。 添加 Flask-Admin 后,我开始用它构建管理仪表板。我尝试添加 Fileadmin 模块来控制静态文件:

from flask_admin.contrib.fileadmin import FileAdmin

现在我在尝试访问相应的网络表单后遇到下一个错误:

[2021-12-15 14:14:32,563] ERROR in app: Exception on /admin/blogfileadmin/ [GET]
Traceback (most recent call last):
  File "/home/demino/WebProjects/blog/blog/lib/python3.9/site-packages/flask/app.py", line 2073, in wsgi_app
    response = self.full_dispatch_request()
  File "/home/demino/WebProjects/blog/blog/lib/python3.9/site-packages/flask/app.py", line 1518, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "/home/demino/WebProjects/blog/blog/lib/python3.9/site-packages/flask/app.py", line 1516, in full_dispatch_request
    rv = self.dispatch_request()
  File "/home/demino/WebProjects/blog/blog/lib/python3.9/site-packages/flask/app.py", line 1502, in dispatch_request
    return self.ensure_sync(self.view_functions[rule.endpoint])(**req.view_args)
  File "/home/demino/WebProjects/blog/blog/lib/python3.9/site-packages/flask_admin/base.py", line 69, in inner
    return self._run_view(f, *args, **kwargs)
  File "/home/demino/WebProjects/blog/blog/lib/python3.9/site-packages/flask_admin/base.py", line 368, in _run_view
    return fn(self, *args, **kwargs)
  File "/home/demino/WebProjects/blog/blog/lib/python3.9/site-packages/flask_admin/contrib/fileadmin/__init__.py", line 812, in index_view
    delete_form = self.delete_form()
  File "/home/demino/WebProjects/blog/blog/lib/python3.9/site-packages/flask_admin/contrib/fileadmin/__init__.py", line 495, in delete_form
    delete_form_class = self.get_delete_form()
  File "/home/demino/WebProjects/blog/blog/lib/python3.9/site-packages/flask_admin/contrib/fileadmin/__init__.py", line 425, in get_delete_form
    class DeleteForm(self.form_base_class):
  File "/home/demino/WebProjects/blog/blog/lib/python3.9/site-packages/flask_admin/contrib/fileadmin/__init__.py", line 426, in DeleteForm
    path = fields.HiddenField(validators=[validators.Required()])
AttributeError: module 'wtforms.validators' has no attribute 'Required'

我在2015年的时候就遇到了很多书出版的问题,但是到目前为止我都很快解决了。现在我卡住了,找不到可以提供帮助的信息。

提前致谢。

Edit1:已解决 - 在 flask-admin -> fileadmin init.py 中手动将 validators.required() 调用更改为 validators.DataRequired()。他们在 v1.0.2 (https://wtforms.readthedocs.io/en/stable/changes/#version-1-0-2) 中区分了它们。不确定这里的 Data- 或 Input- 要求到底是正确的。会看到。

已解决 - 在 flask-admin -> fileadmin init.py 中手动将 validators.required() 调用更改为 validators.DataRequired()。他们在 v1.0.2 (https://wtforms.readthedocs.io/en/stable/changes/#version-1-0-2) 中区分了它们。