本文介紹 django.forms.Field.help_text
的用法。
聲明
Field.help_text
help_text
參數允許您為此 Field
指定說明性文本。如果您提供 help_text
,當 Field
由一種方便的 Form
方法(例如 as_ul()
)呈現時,它將顯示在 Field
旁邊。
與模型字段的
一樣,此值不是 automatically-generated 表單中的 HTML-escaped。help_text
這是一個完整的示例Form
,它為它的兩個字段實現了help_text
。我們指定了auto_id=False
來簡化輸出:
>>> from django import forms
>>> class HelpTextContactForm(forms.Form):
... subject = forms.CharField(max_length=100, help_text='100 characters max.')
... message = forms.CharField()
... sender = forms.EmailField(help_text='A valid email address, please.')
... cc_myself = forms.BooleanField(required=False)
>>> f = HelpTextContactForm(auto_id=False)
>>> print(f.as_table())
<tr><th>Subject:</th><td><input type="text" name="subject" maxlength="100" required><br><span class="helptext">100 characters max.</span></td></tr>
<tr><th>Message:</th><td><input type="text" name="message" required></td></tr>
<tr><th>Sender:</th><td><input type="email" name="sender" required><br>A valid email address, please.</td></tr>
<tr><th>Cc myself:</th><td><input type="checkbox" name="cc_myself"></td></tr>
>>> print(f.as_ul()))
<li>Subject: <input type="text" name="subject" maxlength="100" required> <span class="helptext">100 characters max.</span></li>
<li>Message: <input type="text" name="message" required></li>
<li>Sender: <input type="email" name="sender" required> A valid email address, please.</li>
<li>Cc myself: <input type="checkbox" name="cc_myself"></li>
>>> print(f.as_p())
<p>Subject: <input type="text" name="subject" maxlength="100" required> <span class="helptext">100 characters max.</span></p>
<p>Message: <input type="text" name="message" required></p>
<p>Sender: <input type="email" name="sender" required> A valid email address, please.</p>
<p>Cc myself: <input type="checkbox" name="cc_myself"></p>
相關用法
- Python Django Field.description用法及代碼示例
- Python Django Field.type_name用法及代碼示例
- Python Django Field.width用法及代碼示例
- Python Django Field.label_suffix用法及代碼示例
- Python Django Field.error_messages用法及代碼示例
- Python Django Field.as_datetime用法及代碼示例
- Python Django Field.label用法及代碼示例
- Python Django Field.value用法及代碼示例
- Python Django Field.type用法及代碼示例
- Python Django Field.as_string用法及代碼示例
- Python Django Field.as_int用法及代碼示例
- Python Django Field.default用法及代碼示例
- Python Django Field.as_double用法及代碼示例
- Python Django Field.initial用法及代碼示例
- Python Django Field.name用法及代碼示例
- Python Django Field.precision用法及代碼示例
- Python Django Field.required用法及代碼示例
- Python Django File.save用法及代碼示例
- Python File next()用法及代碼示例
- Python File tell()用法及代碼示例
- Python File seek()用法及代碼示例
- Python OpenCV Filter2D()用法及代碼示例
- Python File writable()用法及代碼示例
- Python File close()用法及代碼示例
- Python Django FileField.upload_to用法及代碼示例
注:本文由純淨天空篩選整理自djangoproject.com大神的英文原創作品 django.forms.Field.help_text。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。