Django模板获取field的verbose_name实例
作者:LiveMost 时间:2023-07-30 06:53:55
创建一个名为templatetags的python module。
新建一个名为verbose_name.py的文件。
from django import template
register = template.Library()
@register.simple_tag
def get_verbose_field_name(instance, field_name):
"""
Returns verbose_name for a field.
"""
return instance._meta.get_field(field_name).verbose_name.title()
在模板页面引入自定义的标签。
{% load verbose_names %}
{% get_verbose_field_name instance field %}
补充知识:django中form的label和verbose name的区别
captcha = CaptchaField(label = u'验证码')
captcha = CaptchaField(verbose_name = u'验证码')
label是这个Field如果在form中的话会显示。
verbose_name 在form中不会显示 只是一种说明而已
来源:https://blog.csdn.net/l497626363/article/details/78660060
标签:Django,field,verbose,name
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
javascript实现延时显示提示框效果
2024-04-25 13:10:42
![](https://img.aspxhome.com/file/2023/0/135550_0s.gif)
php中mysql连接方式PDO使用详解
2023-11-06 02:46:43
Python实现视频中添加音频工具详解
2022-06-03 12:32:28
python re模块findall()函数实例解析
2022-07-07 13:38:40
全国哀悼日 建议站点换素装(附代码)
2008-05-19 12:05:00
MySQL基于DOS命令行登录操作实例(图文说明) <font color=red>原创</font>
2024-01-16 13:54:21
![](https://img.aspxhome.com/file/2023/5/67585_0s.png)
python实现图片彩色转化为素描
2021-12-02 03:57:36
![](https://img.aspxhome.com/file/2023/9/91839_0s.jpg)
Google的设计导引
2008-04-06 14:18:00
Vue中computed和watch的区别
2024-05-29 22:22:50
![](https://img.aspxhome.com/file/2023/4/123174_0s.webp)
Python计算标准差之numpy.std和torch.std的区别
2022-08-17 11:38:14
![](https://img.aspxhome.com/file/2023/4/94094_0s.png)
vue动态添加表单validateField验证功能实现
2023-07-02 17:03:27
MySQL数据库数据删除操作详解
2024-01-13 11:55:42
![](https://img.aspxhome.com/file/2023/4/79134_0s.png)
pandas进行时间数据的转换和计算时间差并提取年月日
2021-03-14 02:22:22
![](https://img.aspxhome.com/file/2023/7/109477_0s.png)
python将一个英文语句以单词为单位逆序排放的方法
2022-03-23 16:48:08
python中super()函数的理解与基本使用
2023-07-02 08:00:33
![](https://img.aspxhome.com/file/2023/0/65520_0s.png)
Python从文件中读取数据的方法步骤
2023-05-05 07:45:32
![](https://img.aspxhome.com/file/2023/7/90657_0s.png)
OpenCV实现车辆识别和运动目标检测
2023-09-22 18:55:40
![](https://img.aspxhome.com/file/2023/6/82606_0s.jpg)
python 实现围棋游戏(纯tkinter gui)
2023-11-23 16:13:04
![](https://img.aspxhome.com/file/2023/4/92074_0s.gif)
主页移动背景代码
2009-11-16 17:54:00
用Dreamweaver实现飘浮光球特效
2008-03-03 12:28:00
![](https://img.aspxhome.com/file/UploadPic/20072/200723113720922s.jpg)