首页 > 其他 > 详细

【3.7】实现最近5篇文章列表

时间:2019-09-03 13:56:31      阅读:57      评论:0      收藏:0      [点我收藏+]

1.从数据库中检索5篇最新文章

1 top5_article_list = Article.objects.all().order_by(-publish_date)[:5]

 

2.修改视图函数

1 return render(request, blog/index.html,
2                   {
3                       article_list: page_article_list,
4                       page_num: range(1, page_num + 1),
5                       curr_page: page,
6                       next_page: next_page,
7                       previous_page: previous_page,
8                       top5_article_list: top5_article_list
9                   })

 

3.修改HTML页面

1 <h2>最新文章</h2>
2                 {% for article in top5_article_list %}
3                 <h4><a href="/blog/detail/{{ article.article_id }}">{{ article.title }}</a></h4>
4                 {% endfor %}

 

【3.7】实现最近5篇文章列表

原文:https://www.cnblogs.com/zydeboke/p/11452257.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!