4👍
You can do this directlly without the init method
password1 = forms.CharField(widget=forms.PasswordInput(
attrs={'class':'form-control','type':'password', 'name': 'password','placeholder':'Password'}),
label='')
0👍
Ngawang13’s answer solved the issue in the questions for me – i.e. the class was set to form-control
.
However, to expand on Ngawang13’s answer, if you wanted to use this field in multiple places, you could create a custom field class.
class MyCustomPasswordField(forms.CharField):
def __init__(self, **kwargs,):
self.widget = forms.PasswordInput(attrs={'class': 'form-control', 'placeholder': 'Password'})
super().__init__(**kwargs)
- [Django]-Heroku Django app not loading static files (404 Not Found)
- [Django]-How to get SelectDateWidget in Django to show different "Year" options
- [Django]-Django url validation
- [Django]-How to add multiple many to many data in django shell
- [Django]-Which built-in Postgres replication fits my Django-based use-case best?
Source:stackexchange.com