How can I make a label bold in a Django form?
The form element goes like this:
condition = forms.TypedChoiceField(label="My Condition is",
coerce= int,
choices=Listed.CONDITION,
widget=RadioSelect(attrs={"class": "required"})
)
Usually, the easiest way would be to do it in your CSS. label[for="id_condition"]{font-weight:bold;}
if you're only dealing with browsers that have attribute selectors implemented. These days, that means everything but IE6. If you do need to support IE6, you can wrap the field in a div and style it that way:
<div class="bold-my-labels">{{ form.condition.label_tag }}{{ form.condition }}</div>
<style type="text/css">.bold-my-labels label{font-weight:bold;}</style>
Lastly, if you need to do it on the Python side of things, you can always stick the HTML in your label arg, a-la "<strong>My Condition is</strong>"
. But it'll get escaped in the HTML unless you mark it as safe, so you'd end up with:
from django.utils.safestring import mark_safe
...
condition = forms.TypedChoiceField(
label=mark_safe("<strong>My Condition is</strong>"),
...
)
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