class UserForm(forms.ModelForm):confirm_email = forms.EmailField(label="Confirm email")def clean(self):email = self.cleaned_data['email']confirm_email = self.cleaned_data['confirm_email']password = self.cleaned_data['password']if email != confirm_email:raise ValidationError({'confirm_email': "Both email doesn't match."})if len(password) < 8:raise ValidationError({'password': "Password should be of minimum 8 characters."})return super(UserForm, self).clean()class Meta:model = Userfields = ['first_name', 'last_name', 'username', 'email', 'confirm_email', 'password']
{% block content %}<p>Register</p><form action="/account/register/" method="POST">{% csrf_token %}{{ user_form.as_p }}<input type="submit" value="Register"></form>{% endblock %}
def register_view(request):if request.method == "POST":user_form = UserForm(request.POST)if user_form.is_valid:user = user_form.save()return HttpResponseRedirect('/account/registered/')else:user_form = UserForm()return render(request, 'register_view.html', {'user_form': user_form})
Template:class UserForm(forms.ModelForm):confirm_email = forms.EmailField(label="Confirm email")def clean(self):email = self.cleaned_data['email']confirm_email = self.cleaned_data['confirm_email']password = self.cleaned_data['password']if email != confirm_email:raise ValidationError({'confirm_email': "Both email doesn't match."})if len(password) < 8:raise ValidationError({'password': "Password should be of minimum 8 characters."})return super(UserForm, self).clean()class Meta:model = Userfields = ['first_name', 'last_name', 'username', 'email', 'confirm_email', 'password']
{% block content %}<p>Register</p><form action="/account/register/" method="POST">{% csrf_token %}{{ user_form.as_p }}<input type="submit" value="Register"></form>{% endblock %}
def register_view(request):if request.method == "POST":user_form = UserForm(request.POST)if user_form.is_valid:user = user_form.save()return HttpResponseRedirect('/account/registered/')else:user_form = UserForm()return render(request, 'register_view.html', {'user_form': user_form})
--
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...@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/ca83b90f-334d-40cf-8561-fc02462ab80f%40googlegroups.com.