flask_bootstrap.Bootstrap object' has no attribute 'load_css'
提示错误:flask_bootstrap.Bootstrap object' has no attribute 'load_css'
bootstrap-flask在自己的电脑里用得挺好的,但一挂到服务器上就报错。
因为是小白,想快速搭好一个好看点的网站,所以用了flask-bootstrap,现在卡死在这里了:)
希望能够帮忙解答一下,谢谢!
github地址
部分代码如下:
# myapp.pyfrom flask_bootstrap import Bootstrap
app = Flask(__name__)
bootstrap = Bootstrap(app)
...
{# homepage.html #}{% from 'bootstrap/nav.html' import render_nav_item %}
{% block styles %}
<!-- Bootstrap CSS -->
{{ bootstrap.load_css() }}
{% endblock %}
{% block scripts %}
<!-- Optional JavaScript -->
{{ bootstrap.load_js() }}
{% endblock %}
...
完整的错误信息如下:
ERROR:flask.app:Exception on / [GET]Traceback (most recent call last):
File "/srv/data/web/vhosts/default/local/lib/python3.7/site-packages/flask/app.py", line 2311, in wsgi_app
response = self.full_dispatch_request()
File "/srv/data/web/vhosts/default/local/lib/python3.7/site-packages/flask/app.py", line 1834, in full_dispatch_request
rv = self.handle_user_exception(e)
File "/srv/data/web/vhosts/default/local/lib/python3.7/site-packages/flask/app.py", line 1737, in handle_user_exception
reraise(exc_type, exc_value, tb)
File "/srv/data/web/vhosts/default/local/lib/python3.7/site-packages/flask/_compat.py", line 36, in reraise
raise value
File "/srv/data/web/vhosts/default/local/lib/python3.7/site-packages/flask/app.py", line 1832, in full_dispatch_request
rv = self.dispatch_request()
File "/srv/data/web/vhosts/default/local/lib/python3.7/site-packages/flask/app.py", line 1818, in dispatch_request
return self.view_functions[rule.endpoint](**req.view_args)
File "./myapp.py", line 28, in home
return render_template('homepage.html',bootstrap = bootstrap)
File "/srv/data/web/vhosts/default/local/lib/python3.7/site-packages/flask/templating.py", line 135, in render_template
context, ctx.app)
File "/srv/data/web/vhosts/default/local/lib/python3.7/site-packages/flask/templating.py", line 117, in _render
rv = template.render(context)
File "/srv/data/web/vhosts/default/local/lib/python3.7/site-packages/jinja2/asyncsupport.py", line 76, in render
return original_render(self, *args, **kwargs)
File "/srv/data/web/vhosts/default/local/lib/python3.7/site-packages/jinja2/environment.py", line 1008, in render
return self.environment.handle_exception(exc_info, True)
File "/srv/data/web/vhosts/default/local/lib/python3.7/site-packages/jinja2/environment.py", line 780, in handle_exception
reraise(exc_type, exc_value, tb)
File "/srv/data/web/vhosts/default/local/lib/python3.7/site-packages/jinja2/_compat.py", line 37, in reraise
raise value.with_traceback(tb)
File "/srv/data/web/vhosts/default/templates/homepage.html", line 5, in top-level template code
{% block styles %}
File "/srv/data/web/vhosts/default/templates/homepage.html", line 7, in block "styles"
{{ bootstrap.load_css() }}
jinja2.exceptions.UndefinedError: 'flask_bootstrap.Bootstrap object' has no attribute 'load_css'```
回答:
建议自己不要用 flask-bootstrap 插件,而是自己导入 bootstrap。
参见这个资料:https://www.jianshu.com/p/d30...
以上是 flask_bootstrap.Bootstrap object' has no attribute 'load_css' 的全部内容, 来源链接: utcz.com/p/937620.html