2

我使用该django-email-as-username应用程序使用电子邮件而不是用户名进行身份验证,它就像一个魅力。

现在,鉴于我想打电话

if request.user.is_authenticated()

但是这种方法只是根据(用户名+密码)而不是(电子邮件+密码)对用户进行身份验证。我应该如何处理?

有什么建议吗?

4

1 回答 1

3

在 Django 中,总是is_authenticated()返回实例并且总是返回实例。它与用户名/密码/电子邮件无关,也不会改变这种行为。TrueUserFalseAnonymousUserdjango-email-as-username

查看 Django 的源代码

# In User class line 279
def is_authenticated(self):
    """
    Always return True. This is a way to tell if the user has been
    authenticated in templates.
    """
    return True
于 2012-06-20T10:33:07.517 回答