-
使用
指定的模板為表單字段呈現標簽標記。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。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。
