【问题标题】:Django if logic in templateDjango if 模板中的逻辑
【发布时间】: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


    【解决方案1】:

    是的,您可以使用as var 语法:

    {% url 'posts:post_detail' pk=instance.id as the_url %}
    ...
    {% if request.path == the_url %}
    ...do something
    {% endif %}
    

    【讨论】:

      猜你喜欢
      • 2012-02-27
      • 2010-12-19
      • 2013-07-25
      • 2013-09-28
      • 1970-01-01
      • 2013-01-24
      • 2019-10-06
      • 2015-05-05
      • 1970-01-01
      相关资源
      最近更新 更多