Lesson 2 / 22 · Commentail 1.3.2
An existing site already has settings, URLs and templates. Add to those files rather than replacing them. Back up the live site and rehearse on a separate copy; lesson 20 covers restoration.
Locate the host configuration
Open the directory containing manage.py. Settings commonly live in myproject/settings/base.py or myproject/settings.py; your project name will differ. Use the settings module that actually runs the site. Activate its existing virtual environment and install commentail==1.3.2. Check the compatibility table in lesson 1 before installation; this is not an instruction to upgrade your whole project.
Add missing commentail and wagtail.contrib.settings entries to INSTALLED_APPS. PostgreSQL installations also need django.contrib.postgres. Do not duplicate existing entries.
# Add only missing apps to the existing list.
INSTALLED_APPS += ["commentail", "wagtail.contrib.settings"]
# Insert this entry immediately before the existing CSRF middleware.
# "commentail.middleware.CapabilityHeadersMiddleware",
# "django.middleware.csrf.CsrfViewMiddleware",
# Optional draft recovery after a rejected CSRF submission.
CSRF_FAILURE_VIEW = "commentail.public.csrf_failure"
The middleware lines above are comments describing placement: insert the real "commentail.middleware.CapabilityHeadersMiddleware", entry immediately before the existing CSRF middleware in MIDDLEWARE. Keep session, authentication and messages middleware. Retain django.template.context_processors.request in your DjangoTemplates backend.
Connect URLs and database tables
Add the Commentail route before Wagtail's final catch-all in the root urls.py, preserving the site's other routes:
from django.urls import include, path
from wagtail import urls as wagtail_urls
urlpatterns = [
# Keep existing admin and application routes above these entries.
path("commentail/", include("commentail.urls")),
path("", include(wagtail_urls)),
]
python manage.py migrate
python manage.py check
python manage.py collectstatic --noinput
Use the project's normal --settings option or DJANGO_SETTINGS_MODULE when needed. collectstatic gathers assets; your deployment must serve STATIC_ROOT using its existing static-file configuration.
Place the widget
Load the resources once in the base template: CSS in <head>, JavaScript in the base template's normal script location.
{% load commentail_tags %}
{% commentail_css %}
{% commentail_js %}
After the article body in its actual Page template add:
{% load commentail_tags %}
{% commentail page %}
page is the current Wagtail Page. In a template using {% extends %}, place the widget inside an existing block such as {% block content %}. Each template using these tags needs its own {% load commentail_tags %}; loading the library in a parent does not load it in the child.
No Page mixin or model field is required. For a computed include, declare its dependency with GET_COMMENT_TEMPLATES in lesson 15.
Check the result
Restart the application using the host's normal process manager. The article must be published under the correct Wagtail Site root. Its editor should show Comments. Sign in with an existing account, submit a message and approve it. Commentail does not supply registration or login. Add guests after configuring mail and the worker. Behind nginx, configure trusted proxies using lesson 19 before public traffic; otherwise visitors may share a proxy's IP quota.
Related lessons
- 1. Start Commentail on a practice site
- 3. Site settings and the reader journey
- 19. Production nginx, caching and user data
Choose a sign-in method or comment as a guest below.