6

Is there a way to apply a class in a form to a {{ field.label_tag }}

I'm using twitter bootstrap and want to add a class to the label tag that field.label_tag

Hopefully there is a way to handle this. I'm using django widget tweaks to do this for the other half of the form for entering the information. Just hoping there is something I've missed that will make it this part just as easy.

okm
  • 23,575
  • 5
  • 83
  • 90
bDreadz
  • 123
  • 1
  • 6

1 Answers1

13

Have you tried manually creating the label element, like so:

<label class="your-class" for="{{ field.auto_id }}">{{ field.label }}</label>

Reference: Looping over Form Fields

Dan LaManna
  • 3,431
  • 4
  • 23
  • 35
  • This is what I do now. I was just hoping to strip the code down a little more. At least I know I'm on the right track. I really like the widget tweaks way of things and had hoped that maybe someone had created something to the same extent. Thanks for the reply. – bDreadz Nov 05 '12 at 02:42
  • Have you considered subclassing BoundField to make your own label_tag method? – Dan LaManna Nov 05 '12 at 03:38