How to add max_length to allauth username

后端 未结 5 1010
孤街浪徒
孤街浪徒 2021-01-25 07:08

I\'m using Django allauth as my user account framework for my django site. The docs show there is an ACCOUNT_USERNAME_MIN_LENGTH however there is no ACCOUNT_USERNAME_MAX_L

5条回答
  •  轮回少年
    2021-01-25 07:26

    You should use a max length validator like below. More documentation about validators here.

    from django.core.validators import MaxLengthValidator
    from allauth.account.forms import SignupForm
    class AllauthSignupForm(SignupForm):
        def __init__(self, *args, **kwargs):
            self.fields['username']['validators'] += MaxLengthValidator(150, "Username should be less than 150 character long")
    

提交回复
热议问题