django模型中的字段和model名显示为中文小技巧分享
作者:hebedich 时间:2021-04-01 15:03:54
简单方法:
models.py
class IceCreamBar(models.Model):
title =
models.CharField(max_length=200,db_index=True,verbose_name="名称")
shell = models.CharField(max_length=100,verbose_name='外皮')
filling = models.CharField(max_length=100,verbose_name='内含')
has_stick = models.BooleanField(default=True,verbose_name='有没有棍')
def __unicode__(self):
return self.title
class Meta:
verbose_name = "冰棒"
verbose_name_plural = "冰棒s"
利用国际化的翻译功能:
models
from django.utils.translation import ugettext_lazy as _
class KarmaUser(AbstractUser):
karma = models.PositiveIntegerField(_("karma"),default=0,blank=True)
然后在message里面设置翻译文本即可.
标签:django,显示中文
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
pycharm将英文设置为中文的详细教程
2022-07-16 14:22:24
![](https://img.aspxhome.com/file/2023/0/127110_0s.png)
对django layer弹窗组件的使用详解
2021-09-08 00:09:38
python发送邮件功能实现代码
2021-04-20 13:51:28
详解Python定时器Timer的使用及示例
2021-01-25 23:54:34
![](https://img.aspxhome.com/file/2023/3/97773_0s.png)
mysql limit查询优化分析
2023-11-16 00:51:04
pytorch geometric的GNN、GCN的节点分类方式
2022-12-24 16:01:23
DIV与Table布局在大型网站的可用性比较
2007-10-08 12:46:00
![](https://img.aspxhome.com/file/UploadPic/200710/8/2007108125233616s.jpg)
GO语言中接口和接口型函数的具体使用
2023-06-18 09:08:40
史上最简单的方法复制或迁移Oracle数据库
2009-02-04 16:38:00
python+OpenCV人脸识别考勤系统实现的详细代码
2021-11-01 01:28:44
关于mysql与mysqli
2011-02-23 12:03:00
Python代码模拟CPU工作原理
2023-08-04 15:23:49
Python实现动态给类和对象添加属性和方法操作示例
2022-05-22 10:58:36
tensorflow+k-means聚类简单实现猫狗图像分类的方法
2022-11-04 10:45:27
![](https://img.aspxhome.com/file/2023/3/85133_0s.gif)
python中and和or逻辑运算符的用法示例
2022-10-13 03:31:18
![](https://img.aspxhome.com/file/2023/0/83890_0s.jpg)
matlab中imadjust函数的作用及应用举例
2021-09-12 21:34:06
![](https://img.aspxhome.com/file/2023/6/82736_0s.jpg)
python类中的self和变量用法及说明
2022-05-27 10:33:12
利用matplotlib+numpy绘制多种绘图的方法实例
2021-02-24 14:10:07
![](https://img.aspxhome.com/file/2023/4/123464_0s.png)
python 5个顶级异步框架推荐
2021-12-23 06:21:47
![](https://img.aspxhome.com/file/2023/5/124335_0s.png)
关于python环境变量如何配置
2023-06-02 14:23:09
![](https://img.aspxhome.com/file/2023/7/98937_0s.jpg)