Hello Tom, 
Django comes inbuilt with user authentication functions which is almost more 
than enough in most of the requirements.In your case, you just need to import 
User model in models.py and in views.py under "if" statement just return 
HttpResponse. You dont need to write anything else. For email and password you 
don't need custom models and views. 
Amitesh

Sent from Yahoo Mail on Android 
 
  On Mon, Nov 20, 2017 at 8:50, Tom Tanner<dontsendemailher...@gmail.com> 
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/94d23f3b-25ee-437d-8302-ad80d6ecc1a1%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
  

-- 
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/1182487239.1624860.1511152196078%40mail.yahoo.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to