首页 > 解决方案 > 带有 css 的 Django 模板条件

问题描述

我的问题是:我想用 css 在 Django 模板中做一个条件,但它没有用。

<label>{% if not typ.required  %}
 {% trans 'Bitte Auswahl treffen' %}{% endif %}</label>
  <input type="checkbox"  {% if typ.required %} style="display:none;" checked="checked"
 {% endif %} name="checkbox"
 data-toggle="toggle" id="{{ typ.typ_id }}"
 value="{{ cookie_id }}" />

{% if typ.required %} style="display:none;" 已检查=“已检查”{% endif %}

checked="checked" 有效,但 Style 无效。

如果我按 f12 观看网站,我会在输入类型中看到这种风格

感谢你们

标签: htmlcssdjangodjango-templates

解决方案


我找到了解决方案。上面的 div 覆盖了复选框的样式:-)


推荐阅读