【问题标题】:code snippets in styling django template bootstrap样式化 django 模板引导程序中的代码片段
【发布时间】:2021-01-28 12:48:47
【问题描述】:

在使用 Bootstrap 为 django 模板设置样式时,我必须包含变量。

<div class="card mb-2 text-white bg-info">

每张卡的信息部分将相应更改。 有没有类似的方法?

<div class="card mb-2 text-white bg-{card.category}">

card 来自各自的型号。

请帮忙

【问题讨论】:

  • 不确定你在问什么——你似乎有答案(尽管在 django 模板中 vars 需要 {{ 而不是 { )。

标签: python python-3.x django bootstrap-4 django-templates


【解决方案1】:

提出条件可能会有所帮助:

<div class="card mb-2 text-white bg-
    {% if card.category==value1 %} class A 
    {% elif card.category==value2 %} class B
    {% else %} class C
    {% endif %}
">

【讨论】:

    猜你喜欢
    • 2020-10-25
    • 1970-01-01
    • 2020-11-25
    • 2014-04-02
    • 1970-01-01
    • 2019-10-13
    • 2018-03-17
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多