I have this rather annoying problem:
In the template I have
<div class="form-group">
{{ form.aboutme.errors }}
<label for="aboutme">About Me:</label>
<textarea class="form-control" rows="10" id="aboutme" value="{{form.aboutme}}"></textarea>
</div>
It renders the textarea pre-populated but with the value but prints a redundant "> at the end of the box.
The raw html looks like this:
<textarea class="form-control" rows="10" id="aboutme" value="<p><textarea cols=" 40"="" name="aboutme">My Name is Django</textarea>
Which obviously has an unintnded textarea tag inserted within.
the field is:
aboutme=models.TextField(blank=True, verbose_name=_('About Me'))
And there is no specia widget used for it in its respective ModelForm class.
So really confused how to correctly render this field?
The textarea html tag has no value attribute. The right syntax is:
<textarea class="form-control" rows="10" id="aboutme">{{ form.aboutme.value }}</textarea>
Read more about widgets.
In this situation you could go with following. Try to get the value from the field:
<textarea class="form-control" rows="10" id="aboutme" value="{{form.aboutme.value}}"></textarea>
If it won't work, using article from link above or following SO question add widget to CharField of your form and then simply use:
{{ form.aboutme }}
As I see you've done it and Django successfuly render <textarea> with <p> tags and populated value. You could try to add more cutomization to widget.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With