Django的认证()仍然返回永诺无 [英] django authenticate() still allways returns None
问题描述
我编辑我的问题与昨日:
<一href=\"http://stackoverflow.com/questions/32741362/django-authenticate-allways-returns-none?noredirect=1#comment53323740_32741362\">django验证()返回永诺无,但我想没有人会会注意的,因为我已经标记了一个问题,回答。
- 身份验证()在外壳工程(昨天没有工作)
- 在我看来,我可以检索用户,并成功地检查其密码
但话又说回来,当我尝试使用身份验证() - 函数在我看来,我得到一个无类型对象。我甚至删除并重新创建数据库,但该行为仍然是相同的。
我的settings.py:
I edited my question from yesterday: django authenticate() allways returns None, but I think noone will will pay attention because I already marked the question as answered. - authenticate() works in the shell (didn't work yesterday) - in my view I can retrieve the user and successfully check its password But then again, when I try to use the authenticate()-function in my view, I get a None-type object. I even deleted and recreated the database but the behaviour is still the same. My settings.py:
MIDDLEWARE_CLASSES = (
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
#'django.contrib.auth.middleware.RemoteUserMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
'django.contrib.staticfiles.finders.FileSystemFinder',
)
AUTHENTICATION_BACKENDS = (
'django.contrib.auth.backends.ModelBackend',
#'django.contrib.auth.backends.RemoteUserBackend',
)
的意见:
从django.contrib.auth.models导入用户
从django.contrib.auth进口身份验证
views: from django.contrib.auth.models import User from django.contrib.auth import authenticate
def authentifizieren(request):
"""
"""
if request.method == 'POST':
uname = request.POST['username']
passwd = request.POST['password']
dbuser = User.objects.get(username=uname)
dbuvalid=dbuser.check_password(passwd)
auser = authenticate(username=uname, password=passwd)
print('***************************************', dbuser,dbuvalid)
print('***************************************', auser)
if (auser != None):
login(request, auser)
return redirect('/startseite')
输出:
*************************************** test True
*************************************** None
我也很难codeD上的用户名/密码字符串exlude编码相关的问题,但没有成功。
顺便说一句,什么是MCVE?
I also hardcoded the user/password-strings to exlude an encoding-related problem, but no success. by the way, what's a MCVE ?
推荐答案
现在验证()的作品。这是一个版本不匹配。现在我还记得,我创建了最初的项目在家里和我的Gentoo的机器上仍然有版本1.7.7安装和Windows机器在工作1.8.4,我认为这是不同的设置文件,愚蠢错误的我。
Now authenticate() works. It was a version-mismatch. Now I remember that I created the initial project at home and on my gentoo-machine there still is the version 1.7.7 installed and on the windows-machine at work 1.8.4., I think it is the different settings-file, stupid mistake from me.
很抱歉给您带来不便
这篇关于Django的认证()仍然返回永诺无的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!