Answer the question
In order to leave comments, you need to log in
It gives an error in the console, how to solve it?
Hello, I have such a problem that in the console it gives the following error:
File "E:\django-site\SiteForMe\news\urls.py", line 9, in
path ( '', ListView.as_view( queryset=Articles. object.all().order_by( '-date' )[:20], templates='news/pots.html' ) )
AttributeError: type object 'Articles' has no attribute 'object';
already searched the Internet, no answer.
I ask you to show or point out the error.
In urls.py file:
from django.urls import path, include
from django.views.generic import ListView, DetailView
from news.models import Articles
urlpatterns = [
path ( '', ListView.as_view( queryset=Articles.object.all().order_by( '-date' )[:20], templates='news/pots.html' ) )
]
from django.db import models
class Articles(models.Model):
title = models.CharField(max_length = 150)
post_body_news = models.TextField()
date = models.DateTimeField()
def __str__(self):
return self.title
Answer the question
In order to leave comments, you need to log in
Everything is ok solved the problem by removing templates='news/pots.html' replaced with a normal function that returns the page
from django.urls import path, include
from django.views.generic import ListView, DetailView
from news.models import Articles
from . import views
urlpatterns = [
path ( '', ListView.as_view( queryset=Articles.objects.all().order_by( '-date' )[:20] ), views.post_news, name='post_news' )
]
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question