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 6641985
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T23:52:35+00:00 2026-05-25T23:52:35+00:00

I have this form field: email = forms.EmailField( required=True, max_length=100, ) It has the

  • 0

I have this form field:

email = forms.EmailField(
  required=True,
  max_length=100,
)

It has the required attribute, but in the html it is not adding the html attribute required. In fact it’s not even using email as the field type, it’s using text… though it appears to get max_length just fine.

Actual:

<input id="id_email" type="text" name="email" maxlength="100">

Expected:

<input id="id_email" type="email" name="email" maxlength="100" required="true">

How can I get Django to use the correct attributes in html forms?

  • 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-25T23:52:36+00:00Added an answer on May 25, 2026 at 11:52 pm

    Monkeypatching Widget is your best bet:

    from django.forms.widgets import Widget
    from django.contrib.admin.widgets import AdminFileWidget
    from django.forms import HiddenInput, FileInput
    
    old_build_attrs = Widget.build_attrs
    
    def build_attrs(self, extra_attrs=None, **kwargs):
        attrs = old_build_attrs(self, extra_attrs, **kwargs)
    
        # if required, and it's not a file widget since those can have files
        # attached without seeming filled-in to the browser, and skip hidden "mock"
        # fileds created for StackedInline and TabbedInline admin stuff
        if (self.is_required
                and type(self) not in (AdminFileWidget, HiddenInput, FileInput)
                and "__prefix__" not in attrs.get("name", "")):
            attrs['required'] = 'required'
    
        return attrs
    
    Widget.build_attrs = build_attrs
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this field in one form : <input type=text name=promocode id=promoCode value= style=width:24%
I have this Form I am trying to upload my image but every time
I have a user registration form that has a password and confirm password field.
I have a Django form with a username and email field. I want to
In my user's data edit form I have a boolean field, for adding/removing email
i have this problem: i have a form with textarea field, and on a
I would like to capture email addresses with this form: I have decided to
I have a bunch of Aweber forms with just a name and email field
I have a very basic email app. The forms class is: class ContactForm(forms.Form): name
I have the following HTML Form: <div id=online_form> <form id=online_form_facebook action=user_form.php name=online_form_facebook> <div class=field>

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.