【发布时间】:2019-10-01 13:39:14
【问题描述】:
我想为 html 属性编写 Django 条件,比如
<a {% if item.link %} href="{{ item.link }}", target="_blank", rel="noopener", aria-label="{{ item }}" {% endif %}>
--- Content ---
</a>
我正在使用 pug/jade,所以我不能将 jam/pug 语法放在“内容”块中,编译器会中断。 我想知道我是否可以以任何方式处理此问题以不重复“内容”块。
我也试过了,没有成功:
a({% if item.link %} href="{{ item.link }}", target="_blank", rel="noopener", aria-label="{{ item }}" {% endif %})
----Content---
【问题讨论】:
-
你试过使用 PyPugJS 之类的东西吗? github.com/kakulukia/pypugjs
-
环顾四周,但没有看到该软件包在哪里解决了我的问题...
-
这是一个用于编写 pug 的系统,可编译为 django 语法。你编写的 pug 条件句会被翻译成 django 条件句。我认为您不会找到同时使用它们的好方法。
标签: django django-templates pug templatetags