最佳答案
我希望 django 通过电子邮件认证用户,而不是通过用户名。一种方法是提供电子邮件值作为用户名值,但我不想这样。原因是,我有一个网址 /profile/<username>/,因此我不能有一个网址 /profile/abcd@gmail.com/。
Another reason being that all emails are unique, but it happen sometimes that the username is already being taken. Hence I'm auto-creating the username as fullName_ID.
我怎样才能改变让 Django 验证电子邮件?
这就是我创建用户的方式。
username = `abcd28`
user_email = `abcd@gmail.com`
user = User.objects.create_user(username, user_email, user_pass)
这是我登录的方式。
email = request.POST['email']
password = request.POST['password']
username = User.objects.get(email=email.lower()).username
user = authenticate(username=username, password=password)
login(request, user)
除了获取用户名之外,还有其他的登录方式吗?