我想制作一个自定义包含标签(如{% smart_include something %}
),它实现了我们想要包含的事物,然后调用常规{% include %}
标签。这应该是这样的:自定义包含标签
@register.simple_tag
def smart_include(something):
if something == "post":
template_name = "post.html"
return regular_include_tag(template_name)
是否有使用{% include %}
标签在Python代码的方式,以及究竟如何?
UPD。回合的出来,要解决这个问题,只是使用render_to_string
快捷
我应该作为'parser'参数发送给这个函数吗? – nukl