我想製作一個自定義包含標籤(如{% 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