-
使用
指定的模板为表单字段呈现标签标记。Form.template_name_label可用的上下文是:
field:的这个实例。BoundFieldcontents:默认情况下,和BoundField.label(或Form.label_suffix,如果设置)的串联字符串。这可以被Field.label_suffixcontents和label_suffix参数覆盖。attrs:包含for、和Form.required_css_classid的dict。id由字段的小部件attrs或生成。BoundField.auto_idattrs参数可以提供其他属性。use_tag:如果标签具有id,则为True的布尔值。如果False默认模板省略<label>标记。
提示
在您的模板中
field是BoundField的实例。因此field.field访问是您声明的字段,例如BoundField.fieldforms.CharField。要单独渲染表单域的标签标签,可以调用其
label_tag()方法:>>> f = ContactForm(data={'message': ''}) >>> print(f['message'].label_tag()) <label for="id_message">Message:</label>如果您想自定义渲染,可以通过覆盖
属性或更一般地通过覆盖默认模板来实现,另请参阅覆盖内置表单模板。Form.template_name_label在 Django 4.0 中更改:现在使用模板引擎呈现标签。
本文介绍 django.forms.BoundField.label_tag 的用法。
声明
BoundField.label_tag(contents=None, attrs=None, label_suffix=None)
相关用法
- Python Django BoundField.id_for_label用法及代码示例
- Python Django BoundField.initial用法及代码示例
- Python Django BoundField.value用法及代码示例
- Python Django BoundField.css_classes用法及代码示例
- Python Django BoundField.errors用法及代码示例
- Python Django BoundField.data用法及代码示例
- Python Django BoundField.name用法及代码示例
- Python Django BoundField.widget_type用法及代码示例
- Python Django BoolOr用法及代码示例
- Python PIL BoxBlur()用法及代码示例
- Python Django BoolAnd用法及代码示例
- Python Bytes转Int用法及代码示例
- Python Bytes转String用法及代码示例
- Python Django BaseCommand.style用法及代码示例
- Python Django BaseFormSet.get_ordering_widget用法及代码示例
- Python Binary转Hexadecimal用法及代码示例
- Python BaseException.with_traceback用法及代码示例
- Python Django BaseFormSet.ordering_widget用法及代码示例
- Python cudf.core.column.string.StringMethods.is_vowel用法及代码示例
- Python torch.distributed.rpc.rpc_async用法及代码示例
- Python torch.nn.InstanceNorm3d用法及代码示例
- Python sklearn.cluster.MiniBatchKMeans用法及代码示例
- Python pandas.arrays.IntervalArray.is_empty用法及代码示例
- Python tf.compat.v1.distributions.Multinomial.stddev用法及代码示例
- Python numpy.less()用法及代码示例
注:本文由纯净天空筛选整理自djangoproject.com大神的英文原创作品 django.forms.BoundField.label_tag。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。
