I would like to put some help text in this form.
class ItemForm(forms.ModelForm):
alternative_id = forms.CharField(max_length = 60, required = False, help_text = 'Valid wildcard search is in the format *XX, *XX*, XX*')
However it does not appear on the page. Is it because I may need a template tag somewhere?
EDIT: I have this written in my template.
<div id="location_header">Search for Items</div>
<div id="form_container">
<form action="." method="post">
<fieldset class="model">
{{ form.as_p }}
{{ alternative_id.help_text }}
</fieldset>
<div id="form_footer">
<input type="submit" value="Search" >
</div>
</form>
</div>
Help text still does not appear. Is there a way to write a help text, while allowing django to generate a form?
Step 1. Read: https://docs.djangoproject.com/en/1.8/topics/forms/#looping-over-the-form-s-fields
Step 2. Customize. Here are the rules.
Within this loop, {{ field }} is an instance of BoundField. BoundField also has the following attributes, which can be useful in your templates:
{{ field.label }} The label of the field, e.g. E-mail address.
{{ field.label_tag }} The field's label wrapped in the appropriate HTML tag, e.g. E-mail address
{{ field.html_name }} The name of the field that will be used in the input element's name field. This takes the form prefix into account, if it has been set.
{{ field.help_text }} Any help text that has been associated with the field.
{{ field.errors }} Outputs a containing any validation errors corresponding to this field. You can customize the presentation of the errors with a {% for error in field.errors %} loop. In this case, each object in the loop is a simple string containing the error message.
Putting {{ form.as_p }}
(or just {{ form }}
) in your template should display the help_text without additional code, provided that you have form
in your context (but I suppose you do if you get the field on your page).
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