Django Contrib Comments

2.2.0 · active · verified Fri Apr 17

django-contrib-comments is a standalone Django application providing a robust system for handling user comments. It was extracted from Django core as of version 1.6 and is actively maintained. The current stable version is 2.2.0, with releases typically aligning with major Django versions.

Common errors

Warnings

Install

Imports

Quickstart

Configure your Django project's `settings.py` and `urls.py` to include `django-contrib-comments`. Ensure `django.contrib.sites` is in `INSTALLED_APPS` and `SITE_ID` is set. After setup, run `python manage.py migrate` to create comment-related database tables. Finally, integrate the comment template tags into your desired templates (e.g., using `{% load comments %}`, `{% render_comment_list for object %}`, and `{% get_comment_form for object as form %}`).

import os

# --- In your project's settings.py ---
INSTALLED_APPS = [
    # Required Django core apps
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'django.contrib.sites', # REQUIRED for django-contrib-comments
    # The comments app itself
    'django_comments',
    # ... your other apps
]

SITE_ID = int(os.environ.get('DJANGO_SITE_ID', 1)) # REQUIRED for django-contrib-comments

# --- In your project's urls.py ---
from django.contrib import admin
from django.urls import path, include

urlpatterns = [
    path('admin/', admin.site.urls),
    # Include the comments app's URLs
    path('comments/', include('django_comments.urls')),
    # ... your application-specific URLs where comments will be rendered
]

# After configuring these, run: python manage.py migrate

view raw JSON →