django 添加comments app

时间:2024-01-12 15:09:50

django 添加comments app

参看 django comments 文档

安装和配置comments

1.安装comments,运行:pip install django-contrib-comments命令

2.settings.py中做如下操作:

  • INSTALLED_APPS下添加'django.contrib.sites'
  • INSTALLED_APPS下添加'django_comments'
  • 定义SITE_ID , SITE_ID = 1

3.令comments app生效

django-admin migrate

4.配置url

  • 修改url.py添加comment app url
urlpatterns = [
...
url(r'^comments/', include('django_comments.urls')),
...
]

5.生成comments表

python manage.py migrate

(blog) [root@localhost blog]# python manage.py migrate

Operations to perform:
Apply all migrations: admin, django_comments, blogpost, sessions, sites, auth, contenttypes
Running migrations:
Rendering model states... DONE
Applying sites.0001_initial... OK
Applying django_comments.0001_initial... OK
Applying django_comments.0002_update_user_email_field_length... OK
Applying django_comments.0003_add_submit_date_index... OK
Applying sites.0002_alter_domain_unique... OK