# forms.py
class UserLoginForm(AuthenticationForm):
class Meta:
model = User
fields = ['username', 'password']
widgets = {
"username": TextInput({
"placeholder": "Введите Email адрес",
"class": "form-control",
}),
"password": PasswordInput({
"placeholder": "Введите свой пароль",
"class": "form-control",
}),
}
# views.py
def sign_in(request):
form = UserLoginForm()
data = {
"form": form
}
return render(request, "main/pages/sign_in.html", data)
<form method="post" class="flex_form">
{% csrf_token %}
{{ form.username }}
<br>
{{ form.password }}
<br>
<button type="submit">Авторизоваться</button>
</form>
Форма есть, но widgets к ней не применился:
Результат на странице:
<form method="post" class="flex_form">
<input type="hidden" name="csrfmiddlewaretoken" value="gZaaiaacfGEh0N3O4Vsts8wcmyga9nJsrKlesQ54zANDa4bsahNwJasGDAo14sCl">
<input type="text" name="username" autofocus="" autocapitalize="none" autocomplete="username" maxlength="150" required="" id="id_username">
<br>
<input type="password" name="password" autocomplete="current-password" required="" id="id_password">
<br>
<button type="submit">Авторизоваться</button>
</form>