レイアウトについて間違った方法で考えている可能性があります。レイアウトはテンプレートの中で最も一般的なものであり、最も複雑なものではありません。自己完結型の機能がほとんど必要ない場合は、include
それらをそのまま、必要な場所に記述します。
つまり、次のようなものが必要な場合:
----------------------------------
+--------------+
Header | Login |
+--------------+
----------------------------------
Body Content (Blog)
また、次のようなスタンドアロンのログイン ページも必要です。
----------------------------------
Header
----------------------------------
+--------------+
| Login |
+--------------+
次に、ログイン パーシャルを作成し、include
必要な場所に配置します。
例
templates/partials/login.html
<form action="/login" method="post">
<!-- Your login goes here -->
</form>
templates/your_base.html
<!DOCTYPE html>
<html>
<head>
{% block head %}
{#
Default HEAD content goes here
with extra nested blocks for children to override
if needed.
#}
{% endblock head %}
</head>
<body>
<header>{% block header %}{% endblock header %}</header>
{# Note: This assumes we *always* want a header #}
{% block content %}{% endblock content %}
</body>
</html>
テンプレート/login.html
{% extends "your_base.html" -%}
{% block content -%}
{% include "partials/login.html" %}
{%- endblock content %}
テンプレート/blog.html
{% extends "your_base.html" -%}
{% block header -%}
{{ super() }}{# Render the default header contents here #}
{% include "partials/login.html" %}
{%- endblock header %}
{% block content -%}
{# Render your blog posts here #}
{%- endblock content %}