【发布时间】:2017-11-18 01:24:49
【问题描述】:
期望的输出:
假设我在 Django 模板中使用 Pug,如果我不想硬编码 URL(我在我的 URL 中将其命名为 artists),并且艺术家数量也是变量?
我可以这样做:
p You're currently following #{user_artists_count} artists
但我怎样才能使最后一部分链接到名称为 artists 的 Django URL?
【问题讨论】:
期望的输出:
假设我在 Django 模板中使用 Pug,如果我不想硬编码 URL(我在我的 URL 中将其命名为 artists),并且艺术家数量也是变量?
我可以这样做:
p You're currently following #{user_artists_count} artists
但我怎样才能使最后一部分链接到名称为 artists 的 Django URL?
【问题讨论】:
您可以使用以下语法在 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
【讨论】: