在html页面中,我试图调用django自定义模板标记,但对我来说,它似乎从未达到模板标记函数。
home.html页面
{% load custom_tags %}
{% if has_profile %}
<p> Creator </p>
{% else %}
<li><a href="{% url 'update_profile' %}" class="btn btn-simple">Become a Creator</a></li>
{% endif %}custom_tags.py
从django导入模板
from users.models import Profile
register = template.Library()
@register.simple_tag
def has_profile():
return 1如果你需要任何信息,请告诉我。谢谢!
发布于 2019-07-07 00:04:11
这不是它的工作方式。if标记中的任何内容都必须是模板变量,而不是标记。
您可以使用as语法将标记的结果保存到变量中,并使用:
{% has_profile as has_profile_result %}
{% if has_profile_result %}
...https://stackoverflow.com/questions/56915549
复制相似问题