我的烧瓶项目中有以下结构:
app
-app
-static
-templates
-layouts
footer.html
header.html
main.html
search.html
__init__.py
app.py
MANIFEST.in
setup.py
在app.py中:
@app.route('/search')
def show_search_form():
return render_template('search.html')
search.html:
{% extends "layouts/main.html" %}
{% block body %}
Test
{% endblock %}
main.html中
{% include 'header.html' %}
{% block content %}
{% endblock %}
{% include 'footer.html' %}
了header.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>App</title>
</head>
<body>
footer.html
</body>
</html>
正如您所看到的,我将main.html扩展到search.html并使用(在本例中)&#39;测试&#39;作为要注入体块的内容。但是它没有用,我收到了以下错误:
jinja2.exceptions.TemplateNotFound: header.html
代码有什么问题?
答案 0 :(得分:3)
由于您的footer.html和header.html文件位于布局目录下,因此您需要在主模板中引用它们:
<强> main.html中强>
{% include 'layouts/header.html' %}
{% block content %}
{% endblock %}
{% include 'layouts/footer.html' %}