Django Python

This page provides details on how to integrate the NotifiedBy service with a Django project. It assumes you have a basic understanding of Django and Python.

Create a blank project

python -m venv venv

source venv/bin/activate

pip install django

pip install django-notifiedby
pip install requests

django-admin startproject test_project

cd test_project

python manage.py migrate

python manage.py runserver

Edit settings.py:

Add “notifiedby” into installed apps.

INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'notifiedby'
]

Add the following code at the end of the file:

EMAIL_BACKEND = "notifiedby.NotifiedByEmailBackend"
NOTIFIEDBY_API_KEY = "YOUR_API_KEY"

Note

Once these are set then any Django generated email will be sent using the NotifiedBy service.

Test Page

Add a views.py file with the following contents, change the YOU@TESTEMAIL to be your own email address. This is using the Django send_mail function so by default it will send as HTML.

from django.http import HttpResponse
from django.core.mail import send_mail

def sendtest(request):

    send_mail(
        "Test email subject",
        "<p><strong>HTML</strong> body of the email goes here</p>",
        "from@is-ignored.com",
        ["YOU@TESTEMAIL"],
        fail_silently=False,
    )

    html = '<html lang="en"><body>Test email sent</body></html>'
    return HttpResponse(html)

Add the following into urlpatterns in urls.py

path('sendtest/', sendtest),

Navigate to http://127.0.0.1:8000/sendtest/ and you should see below and and receive an email:

Send email output

If you log into your account on https://NotifiedBy.com you should see your email there.

Email delivery detail

Note

The email subject has the Django prefix defined in settings.py. Defaults to “[Django]” see the Django docs