[Django]-Django – Render the <label> of a single form field

29👍

https://docs.djangoproject.com/en/dev/topics/forms/#s-looping-over-the-form-s-fields

Shows you can do

{{ FIELD.label_tag }}

Should render something like

<label for="id_fieldName">Fieldlabel:</label>

0👍

You can also do

class SomeForm(forms.Form):
    foo = forms.ChoiceField(label='Some Foo', ...)
    bar = forms.BooleanField(label='Some Bar', ...)

You can render form like:

 <div class="col-12">
        <div class="mb-3">
          {{ form.foo.label }}
          {{ form.foo}}
        </div> 
     </div>

Leave a comment