问题
I want to change in my form the color of the label_suffix.
I just want to set the '*' in red and leave the rest black. Is this possible or do i have to change something in my HTML?
username = forms.CharField(label="Username",label_suffix='*')
回答1:
Get rid of this - label_suffix='*'
. We'll write some CSS to display a *
after the required fields.
First, in your form set an attribute called required_css_class:
class MyForm(...):
required_css_class = 'required'
Django will set a class called required
in the HTML label and input for the field.
Now, put these lines your css file to display a red asterisk:
label.required::after {
content: ' *';
color: red;
}
来源:https://stackoverflow.com/questions/54353923/display-a-red-asterisk-in-django-forms