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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T21:04:37+00:00 2026-05-15T21:04:37+00:00

I have a user registration form that has a password and confirm password field.

  • 0

I have a user registration form that has a “password” and “confirm password” field. When I add “min_length” to my password field and then run the submitted data through my custom clean_confirm_password method, it gives a “Key Error / Password” error.

This occurs when the password field is less than 5 characters, whether the confirm_password field matches or not.

I have tried adding “min_length” to “confirm_password,” but still get the same error.

Everything works fine when I remove “min_length” totally.

Any help is appreciated!

My forms.py file:

class NewUser(forms.Form):
    email = forms.EmailField(max_length=75)
    first_name = forms.CharField(max_length=45)
    last_name = forms.CharField(max_length=45)
    password = forms.CharField(min_length=5, max_length=30, widget=forms.PasswordInput(render_value=False))
    confirm_password = forms.CharField(max_length=30, widget=forms.PasswordInput(render_value=False))

    def clean_confirm_password(self):
        confirm_password = self.cleaned_data['confirm_password']
        original_password = self.cleaned_data['password']
        if original_password != confirm_password:
            raise forms.ValidationError("Password doesn't match")

        return confirm_password
  • 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-15T21:04:38+00:00Added an answer on May 15, 2026 at 9:04 pm

    When you submit a password with fewer than 5 characters, it fails the min_length validation so password is not in your form’s cleaned_data dictionary. When you try to access the missing key, you get a KeyError.

    Instead, you should try:

    original_password = self.cleaned_data.get('password', '')
    

    which will return '' if the password is too short.

    As an aside, a clean_myfieldname method should only rely on one field. If you want to clean and validate fields that rely on each other, use the clean method for this (see the django docs).

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

Sidebar

Related Questions

I have a product registration form that allows the user to add additional product
I have a registration form that a user can access via invitation. For example,
I have a password field in my registration form. The following is the code
I am using ASP.net(2.0) with VB.NET. I have a User registration form. On that
I have a user registration Form. If a new User register their account in
Let's say I have an user registration form. In this form, I have the
I have to do a user registration form (classical layout with two columns, labels
I want to make a user-registration form where I will have fields such first
I have a registration form where this CSS rules apply. when user submits with
In my web application i have registration form, when user register i want to

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.