1

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 type="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>

1 Answer 1

2

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')
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.