-
使用
Form.template_name_label
可用的上下文是:
field
:BoundField
contents
:默認情況下,BoundField.label
Form.label_suffix
Field.label_suffix
contents
和label_suffix
參數覆蓋。attrs
:包含for
、Form.required_css_class
id
的dict
。id
由字段的小部件attrs
或BoundField.auto_id
attrs
參數可以提供其他屬性。use_tag
:如果標簽具有id
,則為True
的布爾值。如果False
默認模板省略<label>
標記。
提示
在您的模板中
field
是BoundField
的實例。因此field.field
訪問BoundField.field
forms.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。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。