Reputation: 59
i I'm beginner in learning Django, I got this error when i try to runserver:
__init__() takes 1 positional argument but 2 were given
the urls:
from django.contrib import admin
from django.urls import path
from users import views as user_views
from main.views import about, ListView
from django.contrib.auth import views as auth_views
from django.conf import settings
from django.conf.urls.static import static
urlpatterns = [
path('admin/', admin.site.urls),
path('register/', user_views.register, name='register'),
path('profile/', user_views.profile, name='profile'),
path('about/', about, name='about'),
path('', ListView, name='PostListViews'),
path('login/', auth_views.LoginView.as_view(template_name='users/login.html'), name='login'),
path('logout/', auth_views.LogoutView.as_view(template_name='users/logout.html'), name='logout'),
]
if settings.DEBUG:
urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
here is my views:
from django.shortcuts import render
from .models import Post
from django.views.generic import ListView
def blog(request):
context = {
'posts': Post.objects.all()
}
return render(request=request,
template_name='main/blog.html',
context=context)
class PostListViews(ListView):
model = Post
template_name = 'main/blog.html'
def about(request):
return render(request=request,
template_name='main/about.html')
i don't know where the error comes from please explain to me and Thank you in advance :)
Upvotes: 0
Views: 1987
Reputation: 614
instead of
path('', ListView, name='PostListViews'),
write
path('', PostListViews.as_view(), name='PostListViews'),
Try it
Upvotes: 4