You can display the username from the form fields as follows:
class RegisterForm(UserCreationForm): def __init__(self, *args, **kwargs): super(RegisterForm, self).__init__(*args, **kwargs)
But then you will need to fill in some random username before saving like this:
from random import choice from string import letters ... class RegisterForm(UserCreationForm): ... def save(self): random = ''.join([choice(letters) for i in xrange(30)]) self.instance.username = random return super(RegisterForm, self).save()
There are other considerations to take when you hack it in such a way as to make sure your LoginForm pulls out the username later when necessary:
class LoginForm(AuthenticationForm): email = forms.EmailField(label=_("E-mail"), max_length=75) def __init__(self, *args, **kwargs): super(LoginForm, self).__init__(*args, **kwargs) self.fields['email'].required = True
Dean quiΓ±anola
source share