首页 > 其他 > 详细

Django1.6添加comments应用的简单过程

时间:2014-03-21 03:00:57      阅读:552      评论:0      收藏:0      [点我收藏+]

今天尝试为自己开发的博客加上评论功能,查看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,就像这样:

bubuko.com,布布扣
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,
)
bubuko.com,布布扣

然后我试着在模板中调用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应用的简单过程,布布扣,bubuko.com

Django1.6添加comments应用的简单过程

原文:http://www.cnblogs.com/cjyfff/p/3614736.html

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