最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

validation - Stop displaying help text from custom password validator using django allauth - Stack Overflow

matteradmin5PV0评论

I am trying to make a custom password validator and I got a problem where the HTML page renders return string from get_help_text(). I found that the help text is being displayed before I enter a password for the signup page, and it is still there after ValidationError occurs due to invalid input

I don't have any html file for the sign up page and I'm seeing the default UI provided by allauth. enter image description here

This is my validators.py

class CustomPasswordValidator:
    def validate(self, password, user=None):
        if (
                len(password) < 8 or
                not contains_uppercase_letter(password) or
                not contains_lowercase_letter(password) or
                not contains_number(password) or
                not contains_special_character(password)
        ):
            raise ValidationError("Password must be at least 8 chracters that are a combination of uppercase letter, lowercase letter, numbers and special characters.")

    def get_help_text(self):
        return "Enter at least 8 characters that are a combination of uppercase letter, lowercase letter, numbers and special characters."
        

def validate_no_special_characters(value):
    if contains_special_character(value):
        raise ValidationError("Cannot contain special characters.")

and this is a part of my settings.py

AUTH_PASSWORD_VALIDATORS = [
    {
      "NAME":"appname.validators.CustomPasswordValidator",
    },
]
...

ACCOUNT_PASSWORD_INPUT_RENDER_VALUE = True

I tried returning empty string in get_help_text() but the html page displayed ul list with no content. I don't even want the list on the html page. How can I do this? enter image description here

Post a comment

comment list (0)

  1. No comments so far