I am using the latest version of django and python 3, When I log in I
get the below error message.

django login() takes 1 positional argument but 2 were given

Please find the code for my login view below.

from django.shortcuts import render, get_object_or_404,redirect
from django.contrib.auth.models import User
from django.contrib.auth import authenticate, login
from authentication.forms import LoginForm, ForgottenPasswordForm, ResetPasswordForm
from authentication.functions import send_user_reset_password_link, resend_password_reset_link
from authentication.models import ResetPassword
# Create your views here.
def login(request):
    error_message = None
    heading = 'Login Form'
    if request.method == 'POST':
        form = LoginForm(request.POST)
        if form.is_valid():
            username = form.cleaned_data['username']
            password = form.cleaned_data['password']
            remember_me = form.cleaned_data['remember_me']
            user = authenticate(request,username=username, password=password)
            if not request.POST.get('remember_me', None):
                #request.session.set_expiry(0)          
            if user is not None:
                login(request, user)
                return redirect('property_index',user.id)
            # A backend authenticated the credentials
            else:
                error_message = 'No login credentials found'
            # No backend authenticated the credentials
    form = LoginForm()
    return render(request,'authentication/forms/login.html',{
        'form':form,
        'error_message':error_message,
        'heading':heading

Answer 1

The trouble is: you override the original django login function. So
you should change import.

from django.contrib.auth import authenticate, login as dj_login

and use

dj_login(request, user)

会话保存的login(request, user, backend=None)和文件内登录函数login(request)重名了。

Django自定义的模型如何使用内置的login方法? ٩( ‘ω‘ )و Django问题

django login() takes 1 positional argument but 2 were given

目录问题:Answer 1总结:问题:I am using the latest version of django and python 3, When I log in Iget the below error message.django login() takes 1 positional argument but 2 were givenPlease find the code for my login view below.from django.shortcuts import Django提供了多种装饰器, 其中login_required可能是经常会使用到的。 这里介绍下四种使用此装饰器的办法。 当然, 在使用前, 记得在工程目录的settings.py中设置好LOGIN_URL 1. URLconf中装饰 from django.contrib.auth.decorators import login_required, permission_required from django.views.generic import TemplateView from .views import VoteView urlpatterns = [
TypeError: testlogin() takes 1 positional argument but 2 were given 错误意思是 testlogin()方法只需要一个参数,但是实际给了两个参数。 下面的代码块是调用 login.py 文件下 Login类 下的 test_login( ) 方法 def test_case(self): #执行的测试用例
报错" init() takes 1 positional argument but 2 were given " 解决:在App的urls.py文件中添加as_view()方法 urlpatterns = [ path('', views.ArticleList.as_view(), name='list'), 如果继续报错:" AttributeError: ‘function’ object has no attribute ‘as_view’ " 可能是装饰器出问题了,比如在类视图上使
使用python3的时候,刚开始使用,把所有的都写在了一个文件中,这不符合类的六大设计原则。就把原来的代码按照类进行了拆分。 关于类的六大设计原则:开放关闭原则,里氏替换原则,依赖倒转原则,接口隔离原则,迪米特原则。这里不作过多的解释,大家可以自行百度。 拆分完之后,使用main方法进行实例调用的时候,发现一直报错“takes 1 positional argument but 2 we...
之前写程序经常会碰到此类问题,确认发现并没有少参数。函数为类下函数,定义时需要添加self参数。 但是!但是!为何Python给self赋值而你不必给self赋值? 创建了一个类MyClass,实例化MyClass得到了MyObject这个对象, 然后调用这个对象的方法MyObject.method(arg1,arg2), 这个过程中Python会自动转为Myclass.mehod(My...
Python点击Pycharm按钮Run的时候出现Type ‘manage.py help <subcommand>‘ for help on a specific subcommand. Python项目迁移 - 报错 - cannot set up a python sdk Python项目迁移时虚拟环境无法成功导入 - pyvenv.cfg - 全局python路径问题 2. Windows 10 - Nvm —— node版本管理工具的安装配置方法 - 报错问题集锦与解决方法 - 工程化 Node 绝对环境隔离 - Node 进阶 CSDN-Ada助手: 非常感谢您分享这篇关于Nvm和Node版本管理的博客,对于那些需要进行工程化Node环境隔离和深入了解Node的开发者们来说,这是非常有用的信息。鼓励您继续分享相关技术知识,并为您建议一个具体的技术博文主题: "如何使用Express.js创建基于Node.js的Web应用程序"。希望这个主题能够为读者们提供有关Node.js、Web应用程序和Express.js的知识和教程。期待您的下一篇博客! 2023年博客之星「城市赛道」年中评选已开启(https://activity.csdn.net/creatActivity?id=10470&utm_source=blog_comment_city ), 博主的原力值在所在城市已经名列前茅,持续创作就有机会成为所在城市的 TOP1 博主(https://bbs.csdn.net/forums/blogstar2023?typeId=3152981&utm_source=blog_comment_city),更有丰厚奖品等你来拿~。 关于Mysql数据库连接Navicat时出现1251报错问题的解决方法 m0_73588329: 我搞好数据库了,弄数据库为了写一个项目,看着视频写,但是connectfactory和c3p0的接口一直写不对,connectionfactory不会写 关于Mysql数据库连接Navicat时出现1251报错问题的解决方法 https://blog.csdn.net/qq_42701659/article/details/129463217 试试这个,修改mysql密码,我闲来无事弄的,可能不太详细点,算是个启发,网上也有资料的 关于Mysql数据库连接Navicat时出现1251报错问题的解决方法 m0_73588329: 我一粘贴自己运行了,密码改了,现在进都进不去了,我服了 LInux rar 命令压缩文件夹(目录) CSDN-Ada助手: 恭喜你,获得了 2023 博客之星评选的入围资格,请看这个帖子 (https://bbs.csdn.net/topics/614962616?utmsource=blogger_star_comment)。 请在这里提供反馈: https://blogdev.blog.csdn.net/article/details/129986459?utmsource=blogger_star_comment。