django搭建个人博客10,文章详细3-评论
2017-05-16 19:52
621 查看
完善article_detail_base.html
增加评论展示以及上下篇导航栏
1.修改ArticleDetailView原生SQL执行语句,增加’上一篇’和’下一篇’导航项def get_context_data(self,**kwargs): context=super(ArticleDetailView,self).get_context_data(**kwargs) artId=self.kwargs.get('article') artDate=tb_articles.objects.get(articleID=artId).created context['comments']=tb_comments.objects.filter(articleID=artId).order_by(F('lefted').desc()) try: art=tb_articles.objects.raw(''' select articleID,title from www_tb_articles where created < %s order by created desc limit 1''',[artDate])[0] context['nextID']=art.articleID context['nextID']=''.join(str(context['nextID']).split('-')) context['nextTitle']=art.title except: context['nextID']="#" context['nextTitle']="没有啦" try: art=tb_articles.objects.raw(''' select articleID,title from www_tb_articles where created >%s order by created asc limit 1''',[artDate])[0] context['prevID']=art.articleID context['prevID']=''.join(str(context['prevID']).split('-')) context['prevTitle']=art.title except: context['prevID']="#" context['prevTitle']="没有啦" return context
2.修改article_detail_base.html,增加评论展示以及‘上一篇’,‘下一篇’导航标签。
<div id="theComments"> {% for o in comments %} <div class="aComment"> <p>{{o.content}}</p> <p class="ip">{{o.IP}}</p> <p class="datetime">{{o.lefted}}</p> </div> {% endfor %} </div>
<div class="sidebar"> <h1>Useful Links</h1> <ul> {% if prevID != "#" %} <li><a href="{% url 'www:articleDetail' 0 prevID %}">上一篇: {{ prevTitle }}</a></li> {% else %} <li><a href="#">上一篇: {{ prevTitle }}</a></li> {% endif %} {% if nextID != "#" %} <li><a href="{% url 'www:articleDetail' 0 nextID %}">下一篇: {{ nextTitle }}</a></li> {% else %} <li><a href="#">下一篇: {{ nextTitle }}</a></li> {% endif %} </ul> </div>
3.效果
4.Github
相关文章推荐
- django搭建个人博客09,文章详细2-评论
- django搭建个人博客05,文章详细页1
- django搭建个人博客04,文章列表
- django搭建个人博客07,编辑文章
- 使用 django-blog-zinnia 搭建个人博客
- 用django在SAE搭建个人博客(二)
- VirtualBox虚拟机ubuntu系统安装及django搭建个人博客
- Django博客功能实现—文章评论的显示
- django搭建个人博客02,表设计(models)
- 使用hexo+github免费搭建个人博客网站超详细教程
- 为个人博客添加文章评论功能
- 个人博客网站的详细搭建过程
- python之django-blog-zinnia 搭建个人博客
- Django制作博客中为文章添加评论
- 搭建个人博客-hexo+github详细完整步骤
- 利用ASP.NET MVC和Bootstrap快速搭建个人博客之文章打赏功能(六)
- 如何使用hugo搭建个人博客(四):添加评论系统disqus
- 使用hexo+github搭建免费个人博客详细教程