0

{% include %}Djangoタグを使用して、1 つのテンプレートが別のテンプレートから変数を継承するようにします。しかし、それは起こっていません。

section.html、継承元のテンプレート:

{% block section1 %}
<p>My cows are home.</p>
--> {{ word_in_template }} <--
{% endblock %}

index.htmlword_in_templateから継承する必要がありsection.htmlます:

{% include "section.html" with word_in_template=word_in_template %}

私も試し{% include "section.html" with word_in_template=word %}ました。

私の見解:

def myblog(request):
    return render_to_response('index.html')

def section(request):
    word = "frisky things."
    return render_to_response('section.html', {'word_in_template':word})

section.htmlChrome での出力:

My cows are home.

--> frisky things. <--

index.htmlChrome での出力:

My cows are home.

--> <--

私はこの解決策に従っていますが、うまくいきません。"frisky things"ロードすると表示されますsection.htmlが、表示されませんindex.html。ただし、ハードコードされた文字列My cows are homeは に表示されindex.htmlます。

私もドキュメントを正しくフォローしていると思います。しかし、私は新しいので、物事を正しく読んでいない可能性があります。私は何を間違っていますか?

4

1 に答える 1