0

我写了这个模板包含标签:

@register.inclusion_tag('blog/post_detail.html')
def post_detail(post, show_meta=True):
    return {
        'post': post,
        'show_meta': show_meta
    }

我这样称呼它:

{% post_detail post show_meta=False %}

这工作得很好。模板正确呈现,show_meta值为False.

但是,如果我将默认值更改为show_meta这样False

def post_detail(post, show_meta=False):

然后,如果我尝试使用 调用它{% post_detail post show_meta=True %},模板仍然呈现为show_meta具有False. 为什么?

4

1 回答 1

1

True并且False默认情况下不在模板上下文中定义,并且根据正常的模板语言规则,不存在的名称被视为 False。尝试传递 0 和 1。

于 2012-06-28T21:49:06.160 回答