如果您覆蓋Django用戶的表單,你可以非常優雅地將其關閉。
class CustomUserCreationForm(UserCreationForm):
"""
The form that handles our custom user creation
Currently this is only used by the admin, but it
將使感,讓用戶對自己以後 「」」 電子郵件= forms.EmailField(所需= TRUE) FIRST_NAME = forms.CharField(所需= TRUE) 姓氏=形式註冊。 CharField(所需= TRUE)
class Meta:
model = User
fields = ('first_name','last_name','email')
,然後在backends.py你可以把
class EmailAsUsernameBackend(ModelBackend):
"""
Try to log the user in treating given username as email.
We do not want superusers here as well
"""
def authenticate(self, username, password):
try:
user = User.objects.get(email=username)
if user.check_password(password):
if user.is_superuser():
pass
else: return user
except User.DoesNotExist: return None
然後在admin.py你可以用
class UserCreationForm(CustomUserCreationForm):
"""
This overrides django's requirements on creating a user
We only need email, first_name, last_name
We're going to email the password
"""
def __init__(self, *args, **kwargs):
super(UserCreationForm, self).__init__(*args, **kwargs)
# let's require these fields
self.fields['email'].required = True
self.fields['first_name'].required = True
self.fields['last_name'].required = True
# let's not require these since we're going to send a reset email to start their account
self.fields['username'].required = False
self.fields['password1'].required = False
self.fields['password2'].required = False
礦有一些其他修改重寫,但這應該讓你在正確的軌道上。
我剛剛進去修改auth_user表來解決這個問題。 – Brandon
迄今爲止處理它的最好方法。謝謝。 – David542
不客氣。 – Brandon