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?
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.
Source: https://ru.stackoverflow.com/questions/419732/
All Articles