Tutorial — Django-comments-xtd 2.9.7 Documentation

Configuration¶

Now that the project is running we are ready to add comments. Edit the settings module, tutorial/settings.py, and add django_comments_xtd and django_comments to INSTALLED_APPS:

INSTALLED_APPS = [ ... 'django_comments_xtd', 'django_comments', 'blog', ]

In addition to that insert the following settings to tell django_comments that the application handling comments will actually be django_comments_xtd. We also want to configure some email related settings:

# Tell django.contrib.comments that the application # handling the comments is django-comments-xtd: COMMENTS_APP = 'django_comments_xtd' # Either enable sending mail messages to the console: EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend' # Or set up the EMAIL_* settings so that Django can send emails: EMAIL_HOST = "smtp.example.com" EMAIL_PORT = "587" EMAIL_HOST_USER = "[email protected]" EMAIL_HOST_PASSWORD = "yourpassword" EMAIL_USE_TLS = True DEFAULT_FROM_EMAIL = "Helpdesk <[email protected]>"

Edit the urls module of the project, tutorial/tutorial/urls.py and mount the URL patterns of django_comments_xtd in the path /comments/. The urls installed with django_comments_xtd include django_comments’ urls too:

fromdjango.urlsimport include, path urlpatterns = [ ... path(r'comments/', include('django_comments_xtd.urls')), ... ]

Now let Django create the tables for the two new applications, and run the development server again:

pythonmanage.pymigrate pythonmanage.pyrunserver

Log in the admin site, localhost:8000/admin/ (user: admin, password: admin), and be sure that the domain field of the Site instance points to the correct domain, which for the development server is expected to be localhost:8000.

The value is used to create comment verifications, follow-up cancellations, etc. Update the value if you were using a different a domain or port other than localhost:8000.

Comment confirmation¶

Before we go any further we need to set up the COMMENTS_XTD_SALT setting. This setting plays an important role during the comment confirmation by mail. It helps obfuscating the comment before the user approves its publication.

django-comments-xtd does not store comments in the server until they have been confirmed. This way there is little to none possible comment spam flooding in the database. Comments are encoded in URLs and sent for confirmation by mail. Only when the user clicks the confirmation URL the comment lands in the database.

This behaviour is disabled for authenticated users, and can be disabled for anonymous users too by simply setting COMMENTS_XTD_CONFIRM_EMAIL to False.

Now let’s append the following entries to the tutorial settings module:

# To help obfuscating comments before they are sent for confirmation. COMMENTS_XTD_SALT = (b"Timendi causa est nescire. " b"Aequam memento rebus in arduis servare mentem.") # Source mail address used for notifications. COMMENTS_XTD_FROM_EMAIL = "[email protected]" # Contact mail address to show in messages. COMMENTS_XTD_CONTACT_EMAIL = "[email protected]"

Tag » Add Comment Section In Django