Ste*_*en 2 django templates django-templates
我有一张Customer桌子,其中一个字段是Status....我想要根据它的值设置包含该字段的单元格的背景颜色,例如状态为"已关闭"的绿色; 黄色表示状态为"待定"等.
这样做的最佳方式是什么......如果将来需要的话,可能很容易修改?
在你的css上为td创建类,如下所示,考虑到你想在html表中显示你的客户表信息,
td.closed{ color: green; }
td.pending{ color: yellow; }
Run Code Online (Sandbox Code Playgroud)
现在在您的模板上,您可以在html表上循环数据库表,在td上可以调用css,如下所示:
<td class="{{ status|lower }}">{{ status }}</td>
Run Code Online (Sandbox Code Playgroud)
希望有所帮助