Python 不要显示模板中浏览次数最多的文章列表
我希望这篇文章先出现,然后是文章的浏览量。 我把网站上最受欢迎的文章列了一个列表,这样这些文章的列表就会按顺序显示在一起,但由于某些原因,它们不会显示在模板中。 我有一个视图模型和文章应该按它排序更多的意见 views.pyPython 不要显示模板中浏览次数最多的文章列表,python,html,django,Python,Html,Django,我希望这篇文章先出现,然后是文章的浏览量。 我把网站上最受欢迎的文章列了一个列表,这样这些文章的列表就会按顺序显示在一起,但由于某些原因,它们不会显示在模板中。 我有一个视图模型和文章应该按它排序更多的意见 views.py class ArticleIndex(ListView): model = Articles template_name = 'news/posts.html' paginate_by = 6 def article_tops(self):
class ArticleIndex(ListView):
model = Articles
template_name = 'news/posts.html'
paginate_by = 6
def article_tops(self):
article_top = Articles.objects.all().order_by('-view')
return {'article_top':article_top}
posts.html
{% for article in object_list %}
<h1> {{ article_top }} </h1>
{% endfor %}
{%用于对象列表%中的项目]
{{article_top}}
{%endfor%}
您应该在此处将其设置为queryset,如:
类文章索引(ListView):
模型=文章
queryset=Articles.objects.all().order_by('-view')
模板名称='news/posts.html'
分页方式=6
该模板看起来像:
{% for article in object_list %}
<h1> {{ article }} </h1>
{% endfor %}
{%用于对象列表%中的项目]
{{条款}
{%endfor%}
为什么您认为这应该有效?调用article\u tops
方法应该是什么?
{% for article in object_list %}
<h1> {{ article }} </h1>
{% endfor %}