Django Authentication Form Customize, Doubles Field

Viewed 25

The Goal is To Customize Form, Then Pass it to LoginView. I am using AuthenticationForm after Customizing it, but i see it repeats extra one input, I guess it is for username, i need only two inputs, E-Mail and Password. any advice.

Forms:

class AccountSignInForm(AuthenticationForm):
   email = forms.EmailField(widget=forms.EmailInput(attrs={'placeholder': 'E-Mail..'}), label='E-Mail')
   password = forms.CharField(widget=forms.PasswordInput(attrs={'placeholder': 'Password..'}), label='Password')

   class Meta:
       model = Account
       fields = ['email', 'password']

Views:

class AccountLoginView(LoginView):
   template_name = 'accounts/login.html'
   form_class = AccountSignInForm
   success_url = 'HomePageView'

URLS:

app_name = 'accounts'

urlpatterns = [
    path('sign-in', views.AccountLoginView.as_view(), name='login'),
]

HTML:

<h1>Login Form</h1>
<form method="POST">
    {% csrf_token %}
    {% for field in form %}
        <div>{{ field.label }}</div>
        <div>{{ field }}</div>
    {% endfor %}
    <input type="submit" value="Login" />
</form>

enter image description here Any Ideas,.

1 Answers

Solved With This Method Instead,

class ClientSignInForm(AuthenticationForm):
def __init__(self, *args, **kwargs):
    super(ClientSignInForm, self).__init__(*args, **kwargs)
    self.fields['username'].widget.attrs.update(
        {'placeholder': 'E-Mail ...', 'type': 'email', 'name': 'email', 'id': 'email'})
    self.fields['username'].label = 'E-Mail Address'
    self.fields['password'].widget.attrs.update(
        {'placeholder': 'Password ...', 'type': 'password', 'name': 'password', 'id': 'password'})
    self.fields['password'].label = 'Password'
Related