6👍
I’m 99.9% positive that you missed adding the widget to the form field declaration. You should have something like this in order to display a password field:
class MyForm(forms.Form):
...
password = forms.CharField(widget=forms.PasswordInput)
...
And the layout should be as simple as:
Layout(
PrependedText('password', '@', placeholder="password", autocomplete='off')
)
The widget=
keyword argument is defined on the Django’s forms.CharField
constructor and not on the django-cryspy-forms’ bootstrap.PrependedText
constructor.
You can find more information on Django forms fields here.
UPDATE
If you have a model form, it’s being constructed from your model, either automatically (eg using the admin views), by using modelform_factory
or by defining the ModelForm yourself. Here is an example of the 3rd approach.
class MyModelForm(forms.ModelForm):
class Meta:
fields = (... fields you want to include in the form ...)
password = forms.CharField(widget=forms.PasswordInput, ...)
Please note that by providing your model form field override, you’ll have to also provide attributes like label, help_text (and such) because they will not be automatically copied from the model field.
2👍
I never had good luck with crispy-forms
and formsets, so I just use forms directly in templates. See if that works:
<form method="post">{% csrf_token %}
{{ formset.management_form|crispy }}
{% for form in formset %}
<input id="id_form-{{ forloop.counter0 }}-id" name="form-{{ forloop.counter0 }}-id" type="hidden" value="{{ form.instance.pk }}"/>
{{ form|crispy }}
{% endfor %}
</form>
- [Django]-Using variable instead of field name in Django query comparions
- [Django]-Translate xml string to Python list
0👍
You need to define PasswordInput.
class YourForm(forms.ModelForm):
password = forms.CharField(label='Enter Password',widget=forms.PasswordInput(attrs={'placeholder': 'alphanumeric password'}))
- [Django]-How do I create a user using OAuth2?
- [Django]-Realizing rating in django
- [Django]-App specific default settings in Django?
- [Django]-Python / Django | How to store sent emails?
- [Django]-TruncDate timezone parameter is not working in Django
0👍
Works for me: forms.py file.
class Meta:
model = NewUser
fields = ('email', 'password')
// add this to make password field 'password' type
widgets = {
'password': forms.PasswordInput(attrs={'type': 'password'}),
}
- [Django]-Django URL Mapping: How to remove app name from URL paths?
- [Django]-Feature differentiation: Rails / Django
- [Django]-Adding hours and days to the python datetime
- [Django]-Using DRF serializer to validate a list of dictionaries
- [Django]-How can I use RESTful services with Django + Mongoengine?