Django 2.1.3 Error: __init__() takes 1 positional argument but 2 were given

自闭症网瘾萝莉.ら 提交于 2019-11-29 18:03:40

You need use as_view() at the end of class based views when declaring in the urls:

path('', views.HomeView.as_view(), name='homepage'),

Also, when using login_required decorator, you need to use it on dispatch method of CBV:

from django.contrib.auth.decorators import login_required
from django.utils.decorators import method_decorator

class HomeView(ListView):

    @method_decorator(login_required)
    def dispatch(self, *args, **kwargs):
        return super(HomeView, self).dispatch(*args, **kwargs)
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!