I have some code that looks like:
#form.html
<form action="/form-action" method="post">
{{form.faction.label_tag}}
{{form.faction}}<br />
{{form.character_name.label_tag}}
{{form.character_name}}
</form>
#form.py
class CharacterForm(forms.Form):
FACTION_CHOICES = (
('Sith', 'Sith Empire'),
('Republic', 'Republic Alliance')
)
faction = forms.ChoiceField(choices=FACTION_CHOICES)
character_name = forms.CharField(max_length=100)
However I would like have a specified class on the label tag on the html output. I know I could do:
<form action="/form-action" method="post">
<label for="id_faction" class="foo">{{form.faction.label}}:</label>
{{form.faction}}<br />
<label for="id_character_name" class="bar">{{form.character_name.label}}:</label>
{{form.character_name}}
</form>
I previously used Rails and you can do something along the lines of:
<%= f.label :field, class: "baz" %>
and was hoping there was just as easy of a solution in django. I thought using form.field-name.label_tag(attrs={'class':'custom-class-name'})
was going to work out but alas I am stuck. Any insight is appreciated.