django authenticate()仍然allways返回None [英] django authenticate() still allways returns None

查看:117
本文介绍了django authenticate()仍然allways返回None的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我昨天编辑了我的问题:
django验证()allways返回None ,但我认为没有人会注意,因为我已经将问题标记为已回答。
- authenticate()在shell中工作(昨天没有工作)
- 在我看来,我可以检索用户并成功检查其密码
但是再次,当我尝试使用在我的视图中,authenticate() - 函数,我得到一个无类型的对象。我甚至删除并重新创建了数据库,但行为仍然是一样的。
我的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',
    )

views:
from django.contrib.auth.models import User
from djang o.contrib.auth import authenticate

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

我还硬编码用户/密码 - 字符串排除编码相关的问题,但是没有成功。
的方式,什么是MCVE?

I also hardcoded the user/password-strings to exlude an encoding-related problem, but no success. by the way, what's a MCVE ?

推荐答案

现在authenticate()工作。这是一个版本不匹配。现在我记得我在家里创建了初始项目,而在我的gentoo机器上,仍然安装了1.7.7版本,而在windows-machine上工作的是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.

很抱歉给您带来不便之处

Sorry for the inconvenience

这篇关于django authenticate()仍然allways返回None的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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