I want to add styling to django’s default password reset form such as classes and placeholders
I have the following in my urls.py
JavaScript
x
15
15
1
from django.urls import path
2
from . import views
3
from django.contrib.auth import views as auth_views
4
5
6
urlpatterns = [
7
8
# Password reset paths
9
10
path('password_reset/', auth_views.PasswordResetView.as_view(template_name="main/password_reset.html"),name="reset_password"),
11
path('password_reset_sent/', auth_views.PasswordResetDoneView.as_view(template_name="main/password_reset_sent.html"),name="password_reset_done"),
12
path('reset_password/<uidb64>/<token>/', auth_views.PasswordResetConfirmView.as_view(template_name="main/reset_password.html"),name="password_reset_confirm"),
13
path('reset_password_complete/', auth_views.PasswordResetCompleteView.as_view(template_name="main/reset_password_complete.html"),name="password_reset_complete"),
14
]
15
in the templates
JavaScript
1
6
1
<form action="" method="POST">
2
{% csrf_token %}
3
{{form}}
4
<input type="submit" name="Send email" class="btn btn-primary" >
5
</form>
6
Advertisement
Answer
yes of course you can overwrite django forms.
JavaScript
1
23
23
1
# forms.py
2
3
from django.contrib.auth.forms import PasswordResetForm
4
5
class UserPasswordResetForm(PasswordResetForm):
6
def __init__(self, *args, **kwargs):
7
super(UserPasswordResetForm, self).__init__(*args, **kwargs)
8
9
email = forms.EmailField(label='', widget=forms.EmailInput(attrs={
10
'class': 'your class',
11
'placeholder': 'your placeholder',
12
'type': 'email',
13
'name': 'email'
14
}))
15
16
# urls.py
17
18
from .forms import UserPasswordResetForm
19
20
path('password_reset/', auth_views.PasswordResetView.as_view(
21
template_name='main/password_reset.html',
22
form_class=UserPasswordResetForm),name='password_reset'),
23