Saturday, November 25, 2017

How do I limit my login form to just email and password?

My `models.py` has this:
class MyUser(AbstractBaseUser):
 email
= models.CharField(max_length=254, unique=True)
 USERNAME_FIELD
= "email"

My `forms.py` has this:
class LoginForm(AuthenticationForm):
 email
= forms.EmailField(label=_("Email"), max_length=254)

 
class Meta:
  model
= MyUser
  fields
= ("email",)

When a user goes to "/signin/", Django loads `sign_in.html`:
 <h2>Log in</h2>
 
<form method="post">
  {% csrf_token %}
  {{ login_form.as_p }}
 
<button type="submit">Log in</button>
 
</form>

The form on the template has three fields: Username, Password and Email, in that Order. I want only Email and Password to show up in the form. How do I do that?

--
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+unsubscribe@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/4e9a3109-3dd0-4754-91f2-44731154920c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment