{"id":9666,"library":"django-contrib-comments","title":"Django Contrib Comments","description":"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.","status":"active","version":"2.2.0","language":"en","source_language":"en","source_url":"https://github.com/django/django-contrib-comments","tags":["django","comments","contrib"],"install":[{"cmd":"pip install django-contrib-comments","lang":"bash","label":"Install the package"}],"dependencies":[{"reason":"Core framework dependency, requires Django>=3.2.","package":"Django","optional":false}],"imports":[{"note":"The comments app was moved out of Django core into its own package with Django 1.6.","wrong":"from django.contrib.comments.models import Comment","symbol":"Comment","correct":"from django_comments.models import Comment"},{"note":"The comments app was moved out of Django core into its own package with Django 1.6.","wrong":"from django.contrib.comments.forms import CommentForm","symbol":"CommentForm","correct":"from django_comments.forms import CommentForm"},{"note":"The comments app was moved out of Django core into its own package with Django 1.6.","wrong":"from django.contrib.comments import get_model","symbol":"get_model","correct":"from django_comments import get_model"}],"quickstart":{"code":"import os\n\n# --- In your project's settings.py ---\nINSTALLED_APPS = [\n    # Required Django core apps\n    'django.contrib.admin',\n    'django.contrib.auth',\n    'django.contrib.contenttypes',\n    'django.contrib.sessions',\n    'django.contrib.messages',\n    'django.contrib.staticfiles',\n    'django.contrib.sites', # REQUIRED for django-contrib-comments\n    # The comments app itself\n    'django_comments',\n    # ... your other apps\n]\n\nSITE_ID = int(os.environ.get('DJANGO_SITE_ID', 1)) # REQUIRED for django-contrib-comments\n\n# --- In your project's urls.py ---\nfrom django.contrib import admin\nfrom django.urls import path, include\n\nurlpatterns = [\n    path('admin/', admin.site.urls),\n    # Include the comments app's URLs\n    path('comments/', include('django_comments.urls')),\n    # ... your application-specific URLs where comments will be rendered\n]\n\n# After configuring these, run: python manage.py migrate","lang":"python","description":"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 %}`)."},"warnings":[{"fix":"Install `django-contrib-comments` via pip, update `INSTALLED_APPS` to `'django_comments'`, and adjust all import paths from `django.contrib.comments` to `django_comments`.","message":"The comments application was removed from Django core (django.contrib.comments) in Django 1.6. Projects upgrading from older Django versions must install and configure `django-contrib-comments` as a standalone package.","severity":"breaking","affected_versions":"<1.6 (original Django core), >=1.6 (new package)"},{"fix":"Add `'django.contrib.sites'` to `INSTALLED_APPS` and define `SITE_ID` (e.g., `SITE_ID = 1`) in your `settings.py`.","message":"The `django.contrib.sites` framework and the `SITE_ID` setting are mandatory dependencies for `django-contrib-comments` to function correctly.","severity":"gotcha","affected_versions":"All versions"},{"fix":"After adding `'django_comments'` to `INSTALLED_APPS`, run `python manage.py migrate`.","message":"Database tables for comments will not be created without running Django migrations.","severity":"gotcha","affected_versions":"All versions"},{"fix":"In your template, load the comment tags with `{% load comments %}`. Then use tags like `{% render_comment_list for object %}` and `{% get_comment_form for object as form %}` to display comments and the comment form.","message":"Displaying comments in templates requires specific template tags and context.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-17T00:00:00.000Z","next_check":"2026-07-16T00:00:00.000Z","problems":[{"fix":"Install `django-contrib-comments` (`pip install django-contrib-comments`) and change all imports from `django.contrib.comments` to `django_comments` (e.g., `from django_comments.models import Comment`).","cause":"Attempting to import from the old Django core comments module, which was removed in Django 1.6.","error":"ModuleNotFoundError: No module named 'django.contrib.comments'"},{"fix":"Ensure `'django_comments'` is in `INSTALLED_APPS` and run `python manage.py migrate`.","cause":"The database tables for `django_comments` have not been created or migrations have not been run.","error":"django.db.utils.OperationalError: no such table: django_comments_comment"},{"fix":"Add `'django.contrib.sites'` to `INSTALLED_APPS` and `SITE_ID = 1` (or your site's ID) to your `settings.py`.","cause":"`django-contrib-comments` requires `django.contrib.sites` and a `SITE_ID` setting.","error":"django.core.exceptions.ImproperlyConfigured: You're using the Django \"sites\" framework without having defined the SITE_ID setting."},{"fix":"Add `path('comments/', include('django_comments.urls'))` to your project's `urls.py`.","cause":"The URL patterns for `django_comments` have not been included in your project's `urls.py`.","error":"django.urls.exceptions.NoReverseMatch: Reverse for 'comments-post-comment' not found. 'comments-post-comment' is not a registered namespace."}]}