Answer the question
In order to leave comments, you need to log in
Why doesn't clean work?
Doing registration, Django 1.9 Python 2.7
def signup(request):
user_form = UserCreateForm(data=request.POST)
if request.method == 'POST':
if user_form.is_valid():
username = user_form.clean_username()
password = user_form.clean_password2()
user_form.save()
user = authenticate(username=username, password=password)
login(request, user)
return redirect('/edit')
else:
return index(request, user_form=user_form)
return redirect('/edit')
Answer the question
In order to leave comments, you need to log in
username = user_form.cleaned_data['username']
The clean() method has already worked once, all data must be taken from self.cleaned_data
It would probably be better that way. But in general I advise you to always look at the source.
def signup(request):
user_form = UserCreateForm(data=request.POST)
if request.method == 'POST':
if user_form.is_valid():
model = user_form.save()
user = authenticate(username=model.username, password=model.password)
login(request, user)
return redirect('/edit')
else:
return index(request, user_form=user_form)
return redirect('/edit')
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question