【问题标题】:How to add Conditional CSS class based on Python If statement如何基于 Python If 语句添加条件 CSS 类
【发布时间】:2017-10-07 01:48:11
【问题描述】:

如何在以下示例中添加基于 Python if 语句的条件 CSS 类以显示 has-success has-feedback 表单元素?

<div class="form-group {% if not error_username %} has-success has-feedback {% endif %}">

【问题讨论】:

  • 你没有工作吗?
  • 它没有。我最终运行了{% if error_username %},然后运行 ​​div 类,如果出现错误,然后运行{% else %} 没有错误的 div,最后运行{% endif %},但代码很多。

标签: python jinja2 webapp2


【解决方案1】:

这样写 if 条件。

<div class="form-group {{'has-success has-feedback' if not error_username }}">

【讨论】:

猜你喜欢
  • 2018-09-26
  • 1970-01-01
  • 2018-02-19
  • 1970-01-01
  • 1970-01-01
  • 2020-12-29
  • 2023-01-12
  • 2016-12-04
  • 2015-09-30
相关资源
最近更新 更多