Answer the question
In order to leave comments, you need to log in
How to register without username?
hi how can i do registration without username in django?
views
def signup(request):
user_form = UserCreateForm(data=request.POST)
if request.method == 'POST':
if user_form.is_valid():
username = user_form.cleaned_data['username']
password = user_form.cleaned_data['password2']
user_form.save()
user = authenticate(username=username, password=password)
login(request, user)
return redirect('/blog/new/')
else:
return index(request, user_form=user_form)
return redirect('/auth')
class UserCreateForm(UserCreationForm):
email = forms.EmailField(required=True, widget=forms.widgets.TextInput(attrs={'placeholder': 'Email'}))
first_name = forms.CharField(required=True, widget=forms.widgets.TextInput(attrs={'placeholder': 'First Name'}))
last_name = forms.CharField(required=True, widget=forms.widgets.TextInput(attrs={'placeholder': 'Last Name'}))
username = forms.CharField(widget=forms.widgets.HiddenInput(attrs={'placeholder': 'Username'}))
password1 = forms.CharField(widget=forms.widgets.PasswordInput(attrs={'placeholder': 'Password'}))
password2 = forms.CharField(widget=forms.widgets.PasswordInput(attrs={'placeholder': 'Password Confirmation'}))
def is_valid(self):
form = super(UserCreateForm, self).is_valid()
for f, error in self.errors.iteritems():
if f != '__all_':
self.fields[f].widget.attrs.update({'class': 'error', 'value': strip_tags(error)})
return form
class Meta:
fields = ['email', 'username', 'first_name', 'last_name', 'password1',
'password2']
model = User
Answer the question
In order to leave comments, you need to log in
I noticed that it is difficult to find information on this in the search, all solutions are only in the form of add-ons on top of django-registration. In my case, I assigned the Username field to EmailField
forms.py
I don’t know if I will be able to work with this data for mailing lists and let’s say activations, but so far everything is working.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question