【Flask】flask-bootstrap报错AttributeError: module ‘dominate.tags‘ has no attribute ‘input‘解决方法

简介: 【Flask】flask-bootstrap报错AttributeError: module ‘dominate.tags‘ has no attribute ‘input‘解决方法

问题

在使用flask-bootstrap渲染表单时,报错AttributeError: module 'dominate.tags' has no attribute 'input'

解决方法

修改\venv\Lib\site-packages\flask_bootstrap\forms.py,也就是修改安装的第三方库源码。把tags.input改成tags.input_

tags.input(type=type, _class=' '.join(classes), **kwargs)
改成
tags.input_(type=type, _class=' '.join(classes), **kwargs)
其他地方类似改法

排错记录

报错提示是dominate.tags 没有input属性(或者是个方法?),但是之前很少接触dominate.tags ,不妨完整检查一下。
从下图错误堆栈情况可以看到,是在返回渲染表单时出现了错误。
39c1ea4729a54b1db5eb88a5681973d6.png

  1. 先检查一下表单有没有问题,
    form.py
    from flask_wtf import FlaskForm
    from wtforms import StringField, SubmitField, PasswordField
    from wtforms.validators import DataRequired
    class LoginForm(FlaskForm):
     user_id = StringField("请输入学号:", validators=[DataRequired()])
     name = PasswordField("请输人姓名:", validators=[DataRequired()])
     submit = SubmitField('提交')
    
    很简单的一个表单,应该没有问题。
  2. 再看看app.py

    @app.route('/login', methods=['GET', 'POST'])
    def login():
     form = LoginForm()
     return render_template('login.html',form=form)
    

    同样很常规。(其实这两步没必要,因为错误堆栈从最下面看可以一步定位)。
    4d1130d3d8e94d149f86b75822088da2.png

  3. 直接检查一下tag引用的源文件\venv\Lib\site-packages\dominate\tags.py

    class input_(html_tag):
    '''
    The input element represents a typed data field, usually with a form control
    to allow the user to edit the data.
    '''
    is_single = True
    _input = input_
    

    发现没有input这个类了,改成了input_
    查看了dominate的源码,发现2020年就改了,而flask-bootstrap的库很久没维护了。
    976c304d19154a728b2d8124c2da4afb.png

相关文章
|
3月前
|
机器学习/深度学习 存储 算法
基于Flask+Bootstrap+机器学习的世界杯比赛预测系统
基于Flask+Bootstrap+机器学习的世界杯比赛预测系统
58 0
|
3月前
|
机器学习/深度学习 数据采集 算法
基于Flask+Bootstrap+机器学习的南昌市租房价格预测系统(上)
基于Flask+Bootstrap+机器学习的南昌市租房价格预测系统
55 0
|
7月前
|
Python
python flask 后端报错 ImportError: cannot import name ‘cached_prope‘
问题python flask 后端报错 ImportError: cannot import name ‘cached_prope‘flask程序启动但抛出该错误,是因为werkzeug 版本过高,需要降低版本即可 解决:一般这种情况是需要注意第三方库版本的对应,werkzeug需要0.16.0 版本时 flask的版本应该时1.x.x 的版本,不能是2.x过高的版本。
68 0
|
3月前
|
机器学习/深度学习 数据可视化 Python
基于Flask+Bootstrap+机器学习的南昌市租房价格预测系统(下)
基于Flask+Bootstrap+机器学习的南昌市租房价格预测系统
51 0
|
4月前
|
前端开发
BootStrap让两个控件在一行显示(label和input同行)
BootStrap让两个控件在一行显示(label和input同行)
|
Python
运行项目时flask_sqlalchemy报错AttributeError: ‘LocalStack‘ object has no attribute ‘__ident_func__‘
1.原因 是由于flask_sqlalchemy版本不匹配导致的,我们需要自动获取正确的包版本
642 1
|
前端开发 Python
Python:Flask-Bootstrap和Bootstrap-Flask
Python:Flask-Bootstrap和Bootstrap-Flask
176 0
Python:Flask-Bootstrap和Bootstrap-Flask
flask确定已经按照,日志报错no module named 'flask',成功解决
我的问题在于python版本的问题,更换版本即可,具体原因我也很懵
flask确定已经按照,日志报错no module named 'flask',成功解决
|
Python
Flask - 访问返回字典的接口报错:The view function did not return a valid response. The return type must be a string, tuple, Response instance, or WSGI callable, but it was a dict.
Flask - 访问返回字典的接口报错:The view function did not return a valid response. The return type must be a string, tuple, Response instance, or WSGI callable, but it was a dict.
1422 0
Flask - 访问返回字典的接口报错:The view function did not return a valid response. The return type must be a string, tuple, Response instance, or WSGI callable, but it was a dict.
N..
|
2月前
|
开发框架 前端开发 UED
Bootstrap的CSS组件
Bootstrap的CSS组件
N..
14 0