我希望一个模板使用 Django{% include %}
标签从另一个模板继承一个变量。但它没有发生。
section.html
,要继承的模板:
{% block section1 %}
<p>My cows are home.</p>
--> {{ word_in_template }} <--
{% endblock %}
index.html
,它应该继承word_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.html
在 Chrome 中的输出:
My cows are home.
--> frisky things. <--
index.html
在 Chrome 中的输出:
My cows are home.
--> <--
我正在遵循这个解决方案,但它对我不起作用。"frisky things"
显示我是否加载section.html
但它没有显示在index.html
. 但是,硬编码的字符串My cows are home
显示在index.html
.
我想我也正在关注文档。但我是新来的,所以也许我读错了东西或其他东西。我究竟做错了什么?