i have some necessary fields in my django ModelForm. How can i add a red star (*) after the required fields ?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
I’m going to assume you want this to happen automatically, so here’s one of a few different ways:
Then you can style the asterisk using CSS.
Or, you can add the asterisk using CSS instead if you want:
This one is probably a better option if you want to do other things with the required field as well.
However, if you will not be accessing the fields individually (such as using {{ form.as_p }}), then you can add a property to your ModelForm:
That will define all fields that are required as having the ‘required’ class (and thus, you can use the CSS code I mentioned above to add an asterisk (or whatever else you want to do with it).