简体   繁体   中英

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. How can I exclude "password fields"? thanks for help.

Just delete them in __init__ and update methods where they are used:

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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