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

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)

Leave a Comment