[Django]-Add styling to django Password reset forms

9👍

yes of course you can overwrite django forms.

# forms.py

from django.contrib.auth.forms import PasswordResetForm

class UserPasswordResetForm(PasswordResetForm):
    def __init__(self, *args, **kwargs):
        super(UserPasswordResetForm, self).__init__(*args, **kwargs)

    email = forms.EmailField(label='', widget=forms.EmailInput(attrs={
        'class': 'your class',
        'placeholder': 'your placeholder',
        'type': 'email',
        'name': 'email'
        }))

# urls.py

from .forms import UserPasswordResetForm

path('password_reset/', auth_views.PasswordResetView.as_view(
    template_name='main/password_reset.html',
    form_class=UserPasswordResetForm),name='password_reset'),

2👍

Try Using django-crispy-forms.

Installation

pip install django-crispy-forms

Add it to your INSTALLED_APPS and select the style:

INSTALLED_APPS = [
'crispy_forms',
]
CRISPY_TEMPLATE_PACK = 'bootstrap4'

Load the tag

{% load crispy_forms_tags %}

Now you can style the form

{{ form|crispy }}
    

0👍

Try using django-crispy-forms and/or django-widget-tweaks

0👍

Use Crispy Forms, here is a well explained article about it
CrispyForms

Leave a comment