greyli / bluelog

The 2024 version: https://github.com/greyli/greybook
MIT License
449 stars 657 forks source link

centos 部署时候出现 ‘jinja2.exceptions.TemplateNotFound: bootstrap/nav.html’ #23

Closed bswbatman closed 4 years ago

bswbatman commented 4 years ago

感谢大佬回复:) 部署到Linux时候,gunicorn -b 0.0.0.0:8000 wsgi:app (env-37) [root@VM_0_6_centos bluelog]# gunicorn -b 0.0.0.0:8000 wsgi:app [2019-12-12 19:44:37 +0800] [8202] [INFO] Starting gunicorn 20.0.4 [2019-12-12 19:44:37 +0800] [8202] [INFO] Listening at: http://0.0.0.0:8000 (8202) [2019-12-12 19:44:37 +0800] [8202] [INFO] Using worker: sync [2019-12-12 19:44:37 +0800] [8240] [INFO] Booting worker with pid: 8240

然后顺着ip访问就出现下面的错误 我感觉关键的错误是 jinja2.exceptions.TemplateNotFound: bootstrap/nav.html 这个日志出现很多次

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/root/.pyenv/versions/3.7.0/envs/env-37/lib/python3.7/site-packages/gunicorn/workers/sync.py", line 134, in handle
    self.handle_request(listener, req, client, addr)
  File "/root/.pyenv/versions/3.7.0/envs/env-37/lib/python3.7/site-packages/gunicorn/workers/sync.py", line 190, in handle_request
    util.reraise(*sys.exc_info())
  File "/root/.pyenv/versions/3.7.0/envs/env-37/lib/python3.7/site-packages/gunicorn/util.py", line 625, in reraise
    raise value
  File "/root/.pyenv/versions/3.7.0/envs/env-37/lib/python3.7/site-packages/gunicorn/workers/sync.py", line 175, in handle_request
    respiter = self.wsgi(environ, resp.start_response)
  File "/root/.pyenv/versions/3.7.0/envs/env-37/lib/python3.7/site-packages/flask/app.py", line 2463, in __call__
    return self.wsgi_app(environ, start_response)
  File "/root/.pyenv/versions/3.7.0/envs/env-37/lib/python3.7/site-packages/flask/app.py", line 2449, in wsgi_app
    response = self.handle_exception(e)
  File "/root/.pyenv/versions/3.7.0/envs/env-37/lib/python3.7/site-packages/flask/app.py", line 1878, in handle_exception
    server_error = handler(server_error)
  File "/root/bluelog/bluelog/__init__.py", line 130, in internal_server_error
    return render_template('errors/500.html'), 500
  File "/root/.pyenv/versions/3.7.0/envs/env-37/lib/python3.7/site-packages/flask/templating.py", line 140, in render_template
    ctx.app,
  File "/root/.pyenv/versions/3.7.0/envs/env-37/lib/python3.7/site-packages/flask/templating.py", line 120, in _render
    rv = template.render(context)
  File "/root/.pyenv/versions/3.7.0/envs/env-37/lib/python3.7/site-packages/jinja2/asyncsupport.py", line 76, in render
    return original_render(self, *args, **kwargs)
  File "/root/.pyenv/versions/3.7.0/envs/env-37/lib/python3.7/site-packages/jinja2/environment.py", line 1008, in render
    return self.environment.handle_exception(exc_info, True)
  File "/root/.pyenv/versions/3.7.0/envs/env-37/lib/python3.7/site-packages/jinja2/environment.py", line 780, in handle_exception
    reraise(exc_type, exc_value, tb)
  File "/root/.pyenv/versions/3.7.0/envs/env-37/lib/python3.7/site-packages/jinja2/_compat.py", line 37, in reraise
    raise value.with_traceback(tb)
  File "/root/bluelog/bluelog/templates/errors/500.html", line 1, in top-level template code
    {% extends 'base.html' %}
  File "/root/.pyenv/versions/3.7.0/envs/env-37/lib/python3.7/site-packages/jinja2/environment.py", line 1005, in render
    return concat(self.root_render_func(self.new_context(vars)))
  File "/root/bluelog/bluelog/templates/errors/500.html", line 14, in root
    {% include '_sidebar.html' %}
  File "/root/bluelog/bluelog/templates/base.html", line 12, in root
    type="text/css">
  File "/root/.pyenv/versions/3.7.0/envs/env-37/lib/python3.7/site-packages/jinja2/environment.py", line 830, in get_template
    return self._load_template(name, self.make_globals(globals))
  File "/root/.pyenv/versions/3.7.0/envs/env-37/lib/python3.7/site-packages/jinja2/environment.py", line 804, in _load_template
    template = self.loader.load(self, name, globals)
  File "/root/.pyenv/versions/3.7.0/envs/env-37/lib/python3.7/site-packages/jinja2/loaders.py", line 113, in load
    source, filename, uptodate = self.get_source(environment, name)
  File "/root/.pyenv/versions/3.7.0/envs/env-37/lib/python3.7/site-packages/flask/templating.py", line 60, in get_source
    return self._get_source_fast(environment, template)
  File "/root/.pyenv/versions/3.7.0/envs/env-37/lib/python3.7/site-packages/flask/templating.py", line 89, in _get_source_fast
    raise TemplateNotFound(template)
**jinja2.exceptions.TemplateNotFound: bootstrap/nav.html**
greyli commented 4 years ago

麻烦把 _sidebar.html 模板内容贴上来看看?

greyli commented 4 years ago

另外,你用的 Bootstrap 扩展是哪一个,Flask-Boostrap 还是 Bootstrap-Flask?

bswbatman commented 4 years ago

另外,你用的 Bootstrap 扩展是哪一个,Flask-Boostrap 还是 Bootstrap-Flask? 使用的Flask-Boostrap alembic==1.3.1 beautifulsoup4==4.7.1 blinker==1.4 certifi==2019.3.9 chardet==3.0.4 Click==7.0 dominate==2.4.0 Flask==1.1.1 Flask-Bootstrap==3.3.7.1 Flask-CKEditor==0.4.3 Flask-DebugToolbar==0.10.1 Flask-Dropzone==1.5.4 Flask-Login==0.4.1 Flask-Mail==0.9.1 Flask-Migrate==2.5.2 Flask-Moment==0.9.0 Flask-SQLAlchemy==2.4.1 Flask-WTF==0.14.2 idna==2.8 itsdangerous==1.1.0 Jinja2==2.10.3 Mako==1.1.0 MarkupSafe==1.1.1 python-dateutil==2.8.1 python-dotenv==0.10.3 python-editor==1.0.4 python-http-client==3.2.1 requests==2.22.0 sendgrid==6.1.0 sendgrid-python==0.1.1 six==1.13.0 soupsieve==1.9.1 SQLAlchemy==1.3.11 Unidecode==1.1.1 urllib3==1.25.3 visitor==0.1.3 Werkzeug==0.16.0 WTForms==2.2.1

麻烦把 _sidebar.html 模板内容贴上来看看?

_sidebar.html :

**{% if links %}

Links

{% endif %}

{% if categories %}

Categories

{% endif %}

**
greyli commented 4 years ago

猜测是包的安装问题,卸载掉 Flask-Boostrap 重新安装试试。

bswbatman commented 4 years ago

好的谢谢 已解决