Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

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.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8499549
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T00:41:53+00:00 2026-06-11T00:41:53+00:00

i have some necessary fields in my django ModelForm. How can i add a

  • 0

i have some necessary fields in my django ModelForm. How can i add a red star (*) after the required fields ?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T00:41:55+00:00Added an answer on June 11, 2026 at 12:41 am

    I’m going to assume you want this to happen automatically, so here’s one of a few different ways:

    {% for field in form %}
        <label for="{{ field.auto_id }}">{{ field.label_tag }}
        {% if field.field.required %}
            <span class="required">*</span>
        {% endif %}
        </label>
    {% endfor %}
    

    Then you can style the asterisk using CSS.

    Or, you can add the asterisk using CSS instead if you want:

    <style type="text/css">
        span.required:after { content: '*'; }
    </style>
    {% for field in form %}
        <label for="{{ field.auto_id }}">
        {% if field.field.required %}
            <span class="required">{{ field.label_tag }}</span>
        {% else %}
            {{ field.label_tag }}
        {% endif %}
        </label>
    {% endfor %}
    

    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:

    class FooForm(forms.ModelForm):
        required_css_class = 'required'
    

    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).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a simple JSF+RichFaces form with some fields and obviously a backing bean
The question is in the title. Some explanation: I can't implement necessary mapping. But
I'm making a todo list in django. I have a model with some properties:
I have 'extended' the System.DateTime struct by adding some essential fields to it. Ideally
I have created a library called Fields where I will create some custom fields.
I have 3 tables (for clarity am only listing some fields): Table 1 (
I have some data loaded as a np.ndarray and need to convert it to
I have some arbitrary pixel data that I want to save as a PNG.
I have some text lines like that : vt_wildshade2^508^508 vt_ailleurs2^1188^1188 ... vt_high2^13652^13652 Is it
I have some code on two systems running kernel 2.4.20 and kernel 2.4.38 .

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.