我的主页--> https://xiaosongshine.github.io/ html
我的网站搭建github地址:https://github.com/xiaosongshine/djangoWebs 前端
在INSTALLED_APP添加django_comments和django.contrib.sites两个应用。python
在外部添加 SITE_ID=1。nginx
django的评论库是一个站点,因此须要添加sites的应用并设置当前django工程的站点id=1git
在 urlpatterns 中添加github
接着,修改前端页面显示评论列表和评论提交表单。这些须要使用django_comments的模版标签,在使用标签以前导入加载:数据库
评论列表能够经过django_comments的get_comment_list模版标签获取,以下代码:django
get_comment_list模版标签的用法是for一个模版对象,as是重命名。变量获得的评论加载便可。bash
而评论提交表单,最主要的是提交的url和表单字段。一样也能够经过django_comments的模版标签处理,以下代码:app
这一步须要注意的有两点
1.{% get_comment_form for blog as blog_form %} {% get_comment_list for blog as comments %}中blog就是你的文章内容,个人主页用的是show我就改成了:
{% get_comment_form for show as blog_form %} {% get_comment_list for show as comments %}
2.<input type="hidden" name="next" value="{%url 'detailblog' blog.id%}"/>其中的value="{%url 'detailblog' blog.id%}就是你要刷新的网页url,个人修改成了:
<input type="hidden" name="next" value="/details-{{show.id}}.html"/>
还有一个小技巧:能够经过{{ comments|length}}获取评论总数目,便于统计显示,个人实现:
<li><a href="#" class="icon fa-comment">{{ comments|length}}</a></li>
修改Django文件和其它配置文件以后,必定要重启Uwsgi和Nginx,否则不生效。
Uwsgi和Nginx重启方法:
效果展现
Please Enjoy Yourself
欢迎你们访问个人主页尝试一下,以为有用的话,麻烦小小鼓励一下 ><
我的网站搭建github地址:https://github.com/xiaosongshine/djangoWebs 欢迎访问