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

88👍

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)
👤ruddra

6👍

You need to use as_view() at the end of class-based views when declaring in the URLs. Like this:

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

0👍

In `urls.py replace by this path-code:

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

from django.urls import path
from . import views
 
urlpatterns = [
     path(' ', views.HomeView.as_view(), name='homepage'),
]

Leave a comment