當前位置: 首頁>>代碼示例 >>用法及示例精選 >>正文


Python Django Field.label_suffix用法及代碼示例


本文介紹 django.forms.Field.label_suffix 的用法。

聲明

Field.label_suffix

label_suffix 參數允許您基於每個字段覆蓋表單的 label_suffix

>>> class ContactForm(forms.Form):
...     age = forms.IntegerField()
...     nationality = forms.CharField()
...     captcha_answer = forms.IntegerField(label='2 + 2', label_suffix=' =')
>>> f = ContactForm(label_suffix='?')
>>> print(f.as_p())
<p><label for="id_age">Age?</label> <input id="id_age" name="age" type="number" required></p>
<p><label for="id_nationality">Nationality?</label> <input id="id_nationality" name="nationality" type="text" required></p>
<p><label for="id_captcha_answer">2 + 2 =</label> <input id="id_captcha_answer" name="captcha_answer" type="number" required></p>

相關用法


注:本文由純淨天空篩選整理自djangoproject.com大神的英文原創作品 django.forms.Field.label_suffix。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。