python - 类型 Error/login authenticate() 接受 0 到 1 个位置参数,但给出了 2 个

标签 python django authentication

def loginUser(request):
    if request.method == "POST":
        username = request.POST.get('username')
        password = request.POST.get('pass1')
        user = authenticate(username, password)

        if user is not None:
            login(request, user)
            return redirect( '/')

        else:
            messages.error(request, "Either your email or password is wrong!")
            return render(request, 'loginpage.html')
    return render(request, 'loginpage.html')

每当我在登录页面上输入凭据时,就会出现此错误,我的登录函数也被命名为 loginUser 呢

最佳答案

您需要将凭据作为命名参数传递:

if request.method == 'POST':
    username = request.POST.get('username')
    password = request.POST.get('pass1')
    user = authenticate(<b>username=</b>username, <b>password=</b>password)
    # …

关于python - 类型 Error/login authenticate() 接受 0 到 1 个位置参数,但给出了 2 个,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66733836/

相关文章:

javascript - 类型错误 : Cannot read property 'replace' of undefined - VueJS

asp.net - 在 Application_AuthenticateRequest 期间检测在 Controller 操作上设置了哪些属性

python - 将多个 swagger 文档(来自不同的应用程序)合并到一个 swagger 仪表板 [drf_yasg]

基于 telnet 的 python 办公自动化

python - Django 不包含(或反向包含)

python - Django 中的模板包含和静态包含有什么区别?

python - 如何为 Django 模板中的字段提供类?

java - 如何使用 LDAP Active Directory 验证 JSP 登录页面

python - 如何用lxml提取p标签中的所有内容?

python - Django Rest Framework 不从条件返回响应代码