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

  • Home
  • SEARCH
  • 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 6963467
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T15:47:42+00:00 2026-05-27T15:47:42+00:00

I have registration form and I am using Django-registration. Now, I need to add

  • 0

I have registration form and I am using Django-registration. Now, I need to add css class to each field. Also, if there are validation errors, then css class should be different for the fields which have error. How can I achieve this?

class RegistrationForm(forms.Form):
"""
Form for registering a new user account.

Validates that the requested username is not already in use, and
requires the password to be entered twice to catch typos.

Subclasses should feel free to add any additional validation they
need, but should avoid defining a ``save()`` method -- the actual
saving of collected user data is delegated to the active
registration backend.

"""
error_css_class = 'error'
required_css_class='wanted'

email = forms.EmailField(widget=forms.TextInput(attrs=dict(maxlength=75)),
                         label=_("Email address"))
password1 = forms.CharField(widget=forms.PasswordInput(render_value=False),
                            label=_("Password"))
password2 = forms.CharField(widget=forms.PasswordInput(render_value=False),
                            label=_("Password (again)"))

In html template, I am doing

<div class="row">
<label for="id_email"><span>*</span> Email Address:</label>
{{ form.email }}
</div>

Note Eventually, I ended up using widget_tweaks, which allowed me to do

{{form.email|add_class:"blink"|add_error_class:"error"}}
  • 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-05-27T15:47:43+00:00Added an answer on May 27, 2026 at 3:47 pm

    You can target form fields without adding a class to each field. Just use CSS rules similar to the following, depending on whether you are rendering the form using as_table (the default for the form’s unicode method), as_ul or as_p.

    form tr {...}
    form li {...}
    form p  {...}
    

    For required fields and fields with errors, you can define required_css_class and error_css_class attributes respectively for a form.

    class ContactForm(Form):
        error_css_class = 'error'
        required_css_class = 'required'
    

    For more information see the docs for Styling required or erroneous form rows.

    If you manually render the form fields in your template, you can access the field’s css classes using the css_classes method.

    <div class="row {{ form.email.css_classes }}">
    <label for="id_email"><span>*</span> Email Address:</label>
    {{ form.email }}
    </div>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Server side extjs form validation using zend framework I have extended Zend_Form class to
I am creating a registration form using PHP and jquery with ajax. Each field
I am new to symfony. I have created a registration form using the code:
I have a basic form that I'm using for member registration. I'm using the
I have a registration form leveraging xVal to handle all validation on the form.
I have a registration form where this CSS rules apply. when user submits with
I have a registration form for registering personal attributes. I am using both included
I'm building my first CodeIgniter app - and have a registration form. I'm using
I have implemented a registration/login/authentication system using this Django guide . But, how would
I have a 3-part registration form using PHP: page 1 : collects info -

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.