我有一个自定义模板标签,显示日历.我想根据动态值填充日历上的某些项目.
这是标签:
@register.inclusion_tag("website/_calendar.html") def calendar_table(post): post=int(post) imp=IMP.objects.filter(post__pk=post) if imp: ...do stuff
在我的模板中,当我传递硬编码值时,它可以正常工作,例如
{% load inclusion_tags %} {% calendar_table "6" %}
但是,当我尝试类似{%calendar_table“{{post.id}}”%}的内容时,会为int()尝试引发一个错误ValueError.我怎么能绕过这个?