Django的身份验证返回None [英] Django Authenticate returns None

查看:948
本文介绍了Django的身份验证返回None的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下的code片断:

I have the following code snippet:

user = User(username='h@h.com',email='h@h.com')
user.set_password('pass')
user.save()
u = authenticate(username='h@h.com', password='pass') #this always returns None!!!

问题是,U总是无。我跟着其他堆栈溢出职位code样品,并已缩小到上面的线路。

The problem is, u is always None. I've followed code samples on other stack overflow posts and have narrowed it down to the above lines.

任何想法,以什么可能发生?

Any ideas as to what might be happening?

推荐答案

把这样的事情在你的设置

Put something like this in your settings

#Authentication backends
AUTHENTICATION_BACKENDS = (
        'django.contrib.auth.backends.ModelBackend',
    )

或者如果你使用的是userena为您的帐户

or if you are using userena for your accounts

#Authentication backends
AUTHENTICATION_BACKENDS = (
    'userena.backends.UserenaAuthenticationBackend',
    'guardian.backends.ObjectPermissionBackend',
    'django.contrib.auth.backends.ModelBackend',
)

这篇关于Django的身份验证返回None的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆