简体   繁体   English

Django如何从UserCreationForm中删除密码字段

[英]Django How To remove the password field from the UserCreationForm

I want to learn somethings about User Authentication.. I want to import UserCreationForm to my forms.py without "password field" and then I want to make password field and control by myself. 我想学习一些关于用户身份验证的事情。我想在没有“密码字段”的情况下将UserCreationForm导入到我的forms.py然后我想自己创建密码字段和控件。 How can I exclude "password fields"? 如何排除“密码字段”? thanks for help. 感谢帮助。

Just delete them in __init__ and update methods where they are used: 只需在__init__删除它们并更新使用它们的方法:

class MyUserCreationForm(UserCreationForm):

   def __init__(self, *args, **kwargs):
       super(MyUserCreationForm, self).__init__(*args, **kwargs)
       del self.fields['password1']
       del self.fields['password2']

Your best option is to hide them from the form: 您最好的选择是将它们隐藏在表单中:

class MyUserCreationForm(UserCreationForm):
    password1 = None # Standard django password input
    password2 = None # Standard django password confirmation input

EDIT: Actually this is only hiding the form, but you will have problems during form validation. 编辑:实际上这只是隐藏表单,但在表单验证过程中会遇到问题。 Still looking for a solution. 仍在寻找解决方案。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM