How to add max_length to allauth username

后端 未结 5 1006
孤街浪徒
孤街浪徒 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:37

    Not sure if this is the best way but it works.

    After extending the SignupForm, Completely changed the username field with a new one that has the max_length parameter.

    from django import forms
    from django.utils.translation import ugettext_lazy as _
    from allauth.account.forms import SignupForm
    
    class AllauthSignupForm(SignupForm):
        username = forms.CharField(label=_("Username"),
                                   min_length=5,
                                   max_length=20, # Change this 
                                   widget=forms.TextInput(
                                       attrs={'placeholder':
                                                  _('Username'),
                                              'autofocus': 'autofocus'}))
    

提交回复
热议问题