标签云

微信群

扫码加入我们

WeChat QR Code

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 like this:class UserForm(ModelForm):class Meta:password = forms.CharField(widget=forms.PasswordInput)model = Userwidgets = {'password': forms.PasswordInput(),}But i am getting the following error: NameError: name 'forms' is not defined. I am using django version 1.4.0. I followed this link : Django password problemsStill getting the same error. What should i do. Where am i getting wrong.Please help


I tried to use PasswordInput as the field definition, which didn't work. The widget=forms.PasswordInput did the trick for me making my form work.

2019年07月24日35分07秒

I tried that too...i am not getting any error now. but getting same text input for password field. also voting the question down will not solve my problem.

2019年07月24日35分07秒

DarHamid I am not tech support. I've answered your question, if you have another problem – ask another question. But may you should debug by yourself for some time? May be you've missed a pair of parentheses somewhere? May be first and second password fields shouldn't have the same name? Trying is the best way to learn.

2019年07月23日35分07秒

I appreciate your answer. But i havnt missed any parenthesis or so. Also i have put name of password field in model class same as that in the modelForm.Thanks any way

2019年07月24日35分07秒

Are the parenthesis really necessary? You just fix the PasswordInput field during initialisation instead of creating them again for every UserForm.

2019年07月23日35分07秒

Not true, Django specifically handles this with if isinstance(widget, type): widget = widget()

2019年07月23日35分07秒

why does django create text field for password? its obvious to have a Password field for the password input?

2019年07月23日35分07秒

A field in django forms is not the same as a field in HTML forms. The field in HTML forms is the same as the widget in django forms.

2019年07月23日35分07秒

This is great to protect newly typed passwords from being displayed. However be aware that this does still leak existing passwords; a user can just "view source" and see the unobscured password in the HTML.

2019年07月24日35分07秒