Reputation: 59
hello guys I'm beginner in learning Django, I got this error when I try to import PostListView from .views
this project urls:
from django.contrib import admin
from django.urls import path, include
from users import views as user_views
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('/', include('main.urls')),
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)
this is my app main urls:
from . import views
from django.urls import path
from main.views import PostListView
urlpatterns = [
path('', PostListView.as_view, name="blog"),
path('about/', views.about, name='about'),
]
and this 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
def about(request):
return render(request=request,
template_name='main/about.html')
Thank you in advance :)
Upvotes: 1
Views: 816
Reputation: 1847
Your class name is defined as PostListViews
instead of PostListVew
. You either need to change the class name, or the name you imported.
Upvotes: 1