I am trying to create some kind of warning when someone enters the username that was already taken. But all i manage to do is to redirect to static page where it says: username picked OR passwords do not match..
this is what i have written in my views.py:
def register_user(request):
if request.method == 'POST':
form = MyRegistrationForm(request.POST)
if form.is_valid():
form.save()
return HttpResponseRedirect('/accounts/register_success')
else:
return render_to_response('invalid_reg.html')
args = {}
args.update(csrf(request))
args['form'] = MyRegistrationForm()
print args
return render_to_response('register.html', args)
and this is my forms.py:
class MyRegistrationForm(UserCreationForm):
email = forms.EmailField(required=True)
class Meta:
model = User
fields = ('username', 'email', 'password1', 'password2')
def save(self, commit=True):
user = super(MyRegistrationForm, self).save(commit=False)
user.email = self.cleaned_data['email']
user.set_password(self.cleaned_data["password1"])
if commit:
user.save()
return user
Please help me :( i have literraly no idea how do i give a proper warning for the user :((
Aucun commentaire:
Enregistrer un commentaire