django - 如何在 django 的 sqlite 数据库中为标题着色?
问题描述
当我添加一张新卡时,我希望每次都可以选择标题颜色。这是我的代码:
from django.db import models
#Create your models here.
class Aziende(models.Model):
immagine = models.ImageField()
nome = models.CharField(max_length=250)
prezzo = models.FloatField()
descrizione = models.CharField(max_length=250)
def __str__(self):
return self.nome
我能怎么做?提前致谢!
解决方案
将颜色作为十六进制代码存储在 CharField 中:
class Aziende(models.Model):
immagine = models.ImageField()
nome = models.CharField(max_length=250)
prezzo = models.FloatField()
descrizione = models.CharField(max_length=250)
colore = models.CharField(max_length=10, default='#FFFFFF')
def __str__(self):
return self.nome
然后将其显示在您的模板中:
<h1 class="title" style="color: {{azienda.colore}}" >{{azienda.nome}}</h1>
推荐阅读
- ios - swift 4.2 Enum case '' not found in type '?' switch 语句中要求冗余解包隐式解包的可选
- c++ - 是否可以获取存储在集合中的对象?C++
- python - 在 Windows 和 Python 中处理文件路径时出错
- javascript - 如何在Angular中(单击)后禁用按钮
- javascript - 为什么我从谷歌地图 API 传递 json 数据时会出错?
- css - 响应式登录栏
- finite-automata - 非确定性有限自动机构造
- tabulator - 是否可以打开其列未折叠的表?
- vba - 循环从列中删除空白单元格
- angular - Jest 测试成功,错误打印到控制台