Django 模板:将 href 属性作为条件处理

New*_*oJS 0 django django-templates

现在,在我的 Django 模板中,a如果条件通过或失败,我正在编写一个全新的标记。有没有一种方法可以在a标签中写入这个条件,以便标签中只有一个?

{% for app in apps %}
    {% if app.app_id == "app-smart" %} 
      <a href='{{app.url}}' class='portfolio-link'>
    {% else %}
      <a href='{% url app.url %}' class='portfolio-link'>
    {% endif %}
{% endfor %}
Run Code Online (Sandbox Code Playgroud)

bru*_*ers 5

很简单:

{% for app in apps %}
  <a href='{% if app.app_id == "app-smart" %}{{app.url}}{% else %}{% url app.url %}{% endif %}' class='portfolio-link'>
{% endfor %}
Run Code Online (Sandbox Code Playgroud)

django 模板没有什么神奇之处,只是纯文本模板。