【发布时间】:2011-07-15 10:31:56
【问题描述】:
我想创建一个可以在多个地方应用的可重用模板(几乎就像 .NET 世界中的 UserControl),例如:
{% for thing in things %}
{% render_thing thing %}
{% endfor %}
render_thing 是我的自定义包含标签。我的 Python 代码如下:
def get_full_path(relative_path):
return os.path.join(os.path.dirname(__file__), relative_path)
def render_thing(thing):
return {'thing':thing }
register = template.create_template_register()
register.inclusion_tag(get_full_path('thing.html'))(render_thing)
thing.html 是我的小模板。但是,当我运行它时,我得到了错误:
TemplateSyntaxError: Invalid block tag: 'render_thing'
我错过了什么?
【问题讨论】:
-
你使用的是什么版本的 Django?应用引擎上的当前默认值相当旧 - 0.96。
-
对,我尝试添加
use_library('django','1.2')代码,但它错误地说它无法识别 use_library :( -
糟糕,忘记导入了。有趣,已修复 - 现在有一个新错误
TemplateSyntaxError: Invalid block tag: 'render_activity', expected 'empty' or 'endfor'
标签: python django google-app-engine django-templates