Hi, guys,
The bellow is my overwriting login form . 

class BaseAuthenticationForm(AuthenticationForm):
    ''' Extends django AuthenticationForm to override username so it's not
      limited by 30 chars since using email auth and emails can be > 30 chars.
    Using 75 as the max_length, since that is the max_length on EmailField;
      yes, no constant to import since django's using a magic # 75.
    '''
    # Use StrippedCharField to strip out leading and trailing spaces in the 
username
    username = StrippedCharField(label="Username", max_length=75,  
widget=FORM.TEXT_INPUT)
    password = forms.CharField(label="Password", widget=FORM.PSWD_INPUT)

When I'm using this in my view function, the form in the web page seems 
strange.

1. debug the project. 
  The login page got "<input class="text" id="id_username" maxlength="64" 
name="username" type="text">"

2. refresh the page,  got "<input class="text" id="id_username" 
maxlength="100" name="username" type="text">"

I don't know why, really confuse me .

If any guys have  met this, Could you please tell me why?  thank you 

and now my solution is :

class BaseAuthenticationForm(AuthenticationForm):

    def __init__(self, *args, **kwargs):
        self.base_fields["username"].widget.attrs["maxlength"] = 75
        self.base_fields["username"].widget.attrs["class"] = "text"
        self.base_fields["password"].widget.attrs["class"] = "text"
        super(BaseAuthenticationForm, self).__init__(*args, **kwargs)
    def clean_username(self):
        username = self.cleaned_data["username"]
        return username.strip()



thank you .
GB.


-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/79a002b4-bfb3-4637-8673-ba67ef0722b5%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to