in the form is transferred

password = forms.CharField(max_length=10, widget=forms.PasswordInput()) 

in the form field is displayed

 <django.forms.widgets.PasswordInput object at 0x0359CC50> 

Why is that?

    1 answer 1

    Your code is absolutely working and there is no difference to transfer there a class or an instance of a class - django itself understands what you gave her. As a confirmation of the similarity code:

     class foo(forms.Form): password = forms.CharField(max_length=10, widget=forms.PasswordInput()) class bar(forms.Form): password = forms.CharField(max_length=10, widget=forms.PasswordInput) print(foo()) print(bar()) 

    will lead

     <tr><th><label for="id_password">Password:</label></th><td><input id="id_password" maxlength="10" name="password" type="password" /></td></tr> <tr><th><label for="id_password">Password:</label></th><td><input id="id_password" maxlength="10" name="password" type="password" /></td></tr> 

    As you can see the result is absolutely identical. Show how you display the form in the template - most likely the problem is precisely this.

    • The problem has already been solved and it was in this, thanks for the attention paid - putch