【问题标题】:how to extend base.html from outside of the package?如何从包外部扩展 base.html?
【发布时间】:2022-01-24 15:11:52
【问题描述】:

我需要在我的其他包中扩展 base.html。

我的应用结构

-flask_blog
|-- app_bone
|     |-- __init__.py
|     |-- blog
|     |     |-- __init__.py
|     |     |-- routes.py
|     |     |-- templates
|     |     |     |-- blog
|     |     |     |     |-- blog.html
|-- templates
|     |-- base.html
-run.py

app_bone/blog/route.py

from flask import render_template, Blueprint

blog = Blueprint('blog', __name__, template_folder='templates')


@blog.route('/')
def blog_list():
    return render_template('blog/blog.html')

app_bone/templates/blog/blog.html

{% extends 'base.html' %}

{% block content %}
<h1> blog </h1>
{% endblock %}

我在运行烧瓶时发现了这个错误

jinja2.exceptions.TemplateNotFound: base.html

【问题讨论】:

    标签: python flask jinja2


    【解决方案1】:

    在 Flask 文档中,您的项目布局应如下所示 https://flask.palletsprojects.com/en/1.0.x/tutorial/layout/ 然后你可以使用这个你的 base.html 文件到达{% extends 'base.html' %}

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-09-27
      • 1970-01-01
      • 2011-09-17
      • 2020-02-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-08-01
      相关资源
      最近更新 更多