How to create password input field in django

前端 未结 9 630
春和景丽
春和景丽 2020-12-28 11:19

Hi I am using the django model class with some field and a password field. Instead of displaying regular plain text I want to display password input. I created a model class

相关标签:
9条回答
  • 2020-12-28 12:16

    ** Try to use this **

    password1 = forms.CharField(widget=forms.PasswordInput(attrs={
        'class': 'input-text with-border', 'placeholder': 'Password'}))
    password2 = forms.CharField(widget=forms.PasswordInput(attrs={
        'class': 'input-text with-border', 'placeholder': 'Repeat Password'}))
    
    0 讨论(0)
  • 2020-12-28 12:22

    What was written by the OP at password = forms.Charfield(widget=forms.PasswordInput) was correct. It just does not belong in the class Meta: section. Instead, it should be above it, indented one level below class UserForm....

    0 讨论(0)
  • 2020-12-28 12:25

    @DrTyrsa is correct. Don't forget your parentheses.

    from django.forms import CharField, Form, PasswordInput
    
    class UserForm(Form):
        password = CharField(widget=PasswordInput())
    
    0 讨论(0)
提交回复
热议问题