【发布时间】:2018-12-30 10:04:29
【问题描述】:
在模板中是否可能出现这样的情况?
{% if request.path == url 'posts:post_detail' pk=instance.id %}
如果没有,我怎样才能达到True 的结果?当用户查看特定帖子(例如post/1)时,我希望这是真的。
【问题讨论】:
标签: django django-templates django-2.0
在模板中是否可能出现这样的情况?
{% if request.path == url 'posts:post_detail' pk=instance.id %}
如果没有,我怎样才能达到True 的结果?当用户查看特定帖子(例如post/1)时,我希望这是真的。
【问题讨论】:
标签: django django-templates django-2.0
是的,您可以使用as var 语法:
{% url 'posts:post_detail' pk=instance.id as the_url %}
...
{% if request.path == the_url %}
...do something
{% endif %}
【讨论】: