Hi Tom , i can solve your code problem . contact me on my mail :- sunilmishra1...@gmail.com
On Monday, November 20, 2017 at 8:50:18 AM UTC+5:30, Tom Tanner wrote: > > I'm following this [tutorial]( > https://simpleisbetterthancomplex.com/tutorial/2017/02/18/how-to-create-user-sign-up-view.html) > > on making simple registration forms in Django. I'd like to make a user > registration form that requires only two fields: "Email" and "Password." No > second password field, just one. > > So far, My `views.py` looks like this: > > def register(request, template="register.html", redirect='/'): > if request.method=="POST": > form= RegisterForm(request.POST) > if form.is_valid(): > form.save() > email= form.cleaned_data.get("email") > raw_password= form.cleaned_data.get("password1") > user= authenticate(email=email, password=raw_password) > login(request, user) > return redirect('/') > else: > form= RegisterForm() > return render(request, template, {"form": form}) > > `forms.py` has this class in it: > > class RegisterForm(UserCreationForm): > email= forms.EmailField(label=_("Email"), max_length=254) > > class Meta: > model= User > fields= ("email",) > > `register.html` looks simple: > > {% extends "base.html" %} > {% block main %} > <h2>Register</h2> > <form method="post"> > {% csrf_token %} > {{ form.as_p }} > <button type="submit">Register</button> > </form> > {% endblock main %} > > In `urls.py`, I have this line in `urlpatterns`: `url("^register/$", > views.register, name="register"),`. > > But my registration forms looks like this, with an Email field and two > Password fields: http://i.imgur.com/b359A5Z.png. And if I fill out all > three fields and hit "Register," I get this error: `UNIQUE constraint > failed: auth_user.username`. > > Any idea why I'm getting this error? And how can I make sure my form only > has two fields: Email and Password? > -- 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+unsubscr...@googlegroups.com. To post to this group, send email to django-users@googlegroups.com. Visit this group at https://groups.google.com/group/django-users. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/36cc7242-a588-4a0c-97ef-c27e6b7e4aa4%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.