【问题标题】:Pug & Django: reverse URL + variable inline?Pug & Django:反向 URL + 变量内联?
【发布时间】:2017-11-18 01:24:49
【问题描述】:

期望的输出:

您目前是following xx artists

假设我在 Django 模板中使用 Pug,如果我不想硬编码 URL(我在我的 URL 中将其命名为 artists),并且艺术家数量也是变量?

我可以这样做:

p You're currently following #{user_artists_count} artists

但我怎样才能使最后一部分链接到名称为 artists 的 Django URL?

【问题讨论】:

    标签: python django pug pyjade


    【解决方案1】:

    您可以使用以下语法在 pug 模板中使用 {% url %} django 标签。

    (我把它放在这里供参考,最近几个小时一直在寻找它。)

    p You're currently 
        - url 'artists' as the_url
        a(href=the_url) following #{user_artists_count} artists
    

    来源:https://docs.djangoproject.com/en/2.1/ref/templates/builtins/#url

    【讨论】:

      猜你喜欢
      • 2019-01-12
      • 1970-01-01
      • 2023-03-26
      • 2012-07-22
      • 2015-05-14
      • 2015-01-07
      • 2010-12-29
      • 1970-01-01
      • 2013-02-28
      相关资源
      最近更新 更多