Django Customizing Form Rendering
When rendering a django form using the as_p method, you traditionally get something like:
<p>Subject: <input type="text" name="subject" maxlength="100" /></p>
if you had defined the following field:
subject = forms.CharField(max_length=100)
Is there some additional property available to fields, that customizes how they are rendered so that you can add arbitrary html to them. To be more specific, I'd like to include some sample text following each of the <p> tags, so instead of the following being rendered:
<p>Subject: <input type="text" name="subject" maxlength="100" /></p>
<p>Message: <input type="text" name="message" value="Hi there" /></p>
<p>Sender: <input 开发者_如何学Gotype="text" name="sender" value="invalid e-mail address" /></p>
This is rendered:
<p>Subject: <input type="text" name="subject" maxlength="100" /></p><div> Sample Text 1 </div>
<p>Message: <input type="text" name="message" value="Hi there" /></p><div> Sample Text 2 </div>
<p>Sender: <input type="text" name="sender" value="invalid e-mail address" /></p><div> Sample Text 3</div>
using help_text
in the form fields renders the sample text as you want, but not in div
<p><label for="id_f1">F1:</label> <input type="text" name="f1" id="id_f1" /> Sample Text 1</p>
field definition
f1 = forms.CharField(help_text='Sample Text 1')
精彩评论