django INCLUDE标记只接受一个参数(不能使用WITH)

时间:2011-05-14 21:01:34

标签: django google-app-engine

当我尝试使用以下内容时

{% include 'stream_doc.html' with doc=draft %}

在我的HTML中(draft是循环迭代上下文中的对象),我收到错误:

  File "C:\Program Files (x86)\Google\google_appengine\lib\django_1_2\django\template\loader_tags.py", line 210, in do_include
raise TemplateSyntaxError("%r tag takes one argument: the name of the template to be included" % bits[0])
TemplateSyntaxError: u'include' tag takes one argument: the name of the template to be included

谁能告诉我发生了什么事?据我所知,我正在关注Django documentation。这是我在app引擎中无法做到的事情吗?

2 个答案:

答案 0 :(得分:6)

在Django 1.2及以下版本中,我相信可以通过

来规避这个问题
{% with draft as doc %}
{% include "stream_doc.html" %}
{% endwith %}

至少它适用于我使用

传递固定值的用例
{% with "Jane" as person %}

答案 1 :(得分:2)

您是否遗漏了与之相关的文档中的“改变Django 1.3”?你的路径表明你正在运行Django 1.2。你应该看the 1.2 documentation