D
D
Dmitry2018-04-07 11:55:59
Django
Dmitry, 2018-04-07 11:55:59

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' ) )

]

In models.py file
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

In particular, I'm making a page for posting news.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
Dmitry, 2018-04-07
@DjangoDev

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' )

]

B
Brake Made, 2018-04-07
@DanilAndreevich

https://stackoverflow.com/questions/7785608/attrib...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question