今天尝试为自己开发的博客加上评论功能,查看Django的文档,发现1.6之后Django不再自带comments这个app了,下面是官方文档上的说明:

Django’s comment framework has been deprecated and is no longer supported. Most users will be better served with a custom solution, or a hosted product like Disqus.

The code formerly known as django.contrib.comments is still available in an external repository.

虽然不再自带,但是仍然可以自己安装实现。根据文档的指引打开下面这个网址

http://django-contrib-comments.readthedocs.org/en/latest/index.html 根据网站中所示的步骤一步一步进行操作:

1. Install the comments app by running pip install django-contrib-comments.

2. Install the comments framework by adding 'django_comments' to INSTALLED_APPS.

3. Run manage.py syncdb so that Django will create the comment tables.

4. Add the comment app’s URLs to your project’s urls.py:

urlpatterns = patterns('',         ...         (r'^comments/', include('django_comments.urls')),         ...     )

5. Use the comment template tags below to embed comments in your templates.

这里需要注意在settings.py的INSTALLED_APPS中,除了增加django_comments外,还需要增加django.contrib.sites,就像这样:

INSTALLED_APPS = (
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'blog',
'text_markup',
'django.contrib.sites',
'django_comments',
)

然后我试着在模板中调用comments:
{% load comments %}
{% get_comment_count for post as comment_count %}
保存后打开网页,会抛出错误提示:AttributeError: 'Settings' object has no attribute 'SITE_ID'
上网搜索了一下,查得这是因为在settings.py中没有指定SITE_ID导致,我猜测是因为刚刚添加的django.contrib.sites需要指定SITE_ID。在settings.py中任意地方添加SITE_ID=1,问题解决。

Django1.6添加comments应用的简单过程的更多相关文章

  1. django 添加comments app

    django 添加comments app 参看 django comments 文档 安装和配置comments 1.安装comments,运行:pip install django-contrib ...

  2. Jenkins+Tomcat+svn+maven自动化构建简单过程

    搭建好jenkins自动化构建之后,点击立即构建,即可将svn服务器上的源码自动编译构建,并打成war包,然后将这个war包以及编译好的项目复制到指定服务器的tomcat容器里,当svn服务器的代码有 ...

  3. 【结果很简单,过程很艰辛】记阿里云Ons消息队列服务.NET接口填坑过程

    Maybe 这个问题很简单,因为解决方法是非常简单,但填坑过程会把人逼疯,在阿里云ONS工作人员.同事和朋友的协助下,经过一天的调试和瞎捣鼓,终于解决了这个坑,把问题记下来,也许更多人在碰到类似问题的 ...

  4. python27+django1.9添加api

    我们进入Python的交互 shell 并使用Django提供的API.要进入Python shell,使用python manage.py shell 使用这个而不是简单的输入"pytho ...

  5. 普通路由器刷开源固件DD-WRT的简单过程

    DD-WRT是基于Linux的无线路由软件,功能强大,它提供了许多一般路由器的软体所没有的功能,将路由器固件升级到DD-WRT可以提升内建于预设固件的限制,并将其转换成强大且具有进阶功能的商业级路由器 ...

  6. Mysql 5.7 Windows 版本(zip)的安装简单过程

    1. 下载zip包 https://cdn.mysql.com//Downloads/MySQL-5.7/mysql-5.7.25-winx64.zip 2. 找一个目录解压缩 3. 简单进行安装: ...

  7. [日常工作] Inspur 服务器安装ESXi的简单过程

    1. 公司里面使用虚拟化来进行功能测试 性能测试, 现阶段和之前主要是用虚拟机来搞. 前期用过hyperV 但是感觉 没有SystemCenter的VMM的授权比较难搞一些. 所以还是用ESXi的多了 ...

  8. vue4——把输入框的内容添加到页面(简单留言板)

    文章地址:https://www.cnblogs.com/sandraryan/ vue最最最简单的demo(记得引入) 实例化一个vue,绑定#app的元素,要渲染的数组arr作为data. 把ar ...

  9. jQuery Validate 表单验证插件----在class属性中添加校验规则进行简单的校验

    一.下载插件包. 网盘下载:https://yunpan.cn/cryvgGGAQ3DSW  访问密码 f224 二.jQuery表单验证插件----添加class属性形式的校验 <!DOCTY ...

随机推荐

  1. Magical Forest

    Problem Description There is a forest can be seen as N * M grid. In this forest, there is some magic ...

  2. css笔记02:选择器(标签式和类)

    body { margin:; padding:; background:#000 url('images/backgrounds/star.png') no-repeat fixed; font: ...

  3. Simple Membership 学习笔记

    第一步:新建项目后添加对WebMartix.Data 和 WebMatrix.WebData的引用第二步:在web.config中添加membership配置节第三步:修改Global.asax文件 ...

  4. FindBugs缺陷库

    1.possible null pointer dereference 解释:某字段可能为空 修复:对应字段使用前判空 2.normal confidence 解释:私有成员变量没有初始化 修复:初始 ...

  5. hibernate 插件安装

    安装hibernate插件 1,help--install new software work with选择All Available Sites 搜索框输入hibernate  会出现所有hiber ...

  6. LeetCode 319

    Bulb Switcher There are n bulbs that are initially off. You first turn on all the bulbs. Then, you t ...

  7. Oracle查找被长时间锁定的对象并kill

    1.用如下语句查找被锁住的表名.OSclient.Session信息 SELECT B.SID         ,B.SERIAL#         ,D.SPID        OS系统进行号    ...

  8. HTTP层 —— Session

    1.简介 由于HTTP驱动的应用是无状态的,所以我们使用Session来存储用户请求信息.Laravel通过干净.统一的API处理后端各种Session驱动,目前支持的流行后端驱动包括Memcache ...

  9. java内存被释放的小例子

    先贴代码: StringBuilder dada = null; ; i<; i++){ dada = new StringBuilder(); ; j<; j++){ dada.appe ...

  10. Asp.net中基于Forms验证的角色验证授权

    Asp.net的身份验证有有三种,分别是"Windows | Forms | Passport",其中又以Forms验证用的最多,也最灵活. Forms 验证方式对基于用户的验证授 ...