Registry / communication / django-templated-mail

django-templated-mail

JSON →
library1.1.1pypypiunverified

Django Templated Mail is a Python library for Django that simplifies sending emails by leveraging Django's powerful template system. It allows developers to define email subject, body (HTML and plain text), and other attributes using standard Django templates. The current version is 1.1.1, and it maintains an active release cadence with regular bug fixes and feature enhancements, particularly for Django version compatibility.

pip install django-templated-mail
INSTALL
IMPORT
SIG · DJANGO-TEMPLATED-M
D
django-templated-mail
communicationpythonv1.1.1
Install
1.5s avg
Import
Disk
16MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v1.1.1 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.920 runs
installs and imports cleanly · install 0.0s · import 0.000s · 17.8MB
glibc
py 3.103.920 runs
installs and imports cleanly · install 1.5s · import 0.000s · 18MB
16MB installed
● package 16MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

BaseEmailMessage
from templated_mail.mail import BaseEmailMessage
from templated_mail import BaseEmailMessage

This quickstart demonstrates how to define a templated email class and send an email using `django-templated-mail`. It sets up minimal Django settings for a runnable example. Remember to create the actual template file (e.g., `my_app/templates/emails/welcome.html`) in your Django project, extending `templated_mail/email.html` and defining `subject`, `html`, and `plain` blocks.

import os import django from django.conf import settings from templated_mail.mail import BaseEmailMessage # Minimal Django setup for demonstration purposes. # In a real Django project, these settings would be in your settings.py # and django.setup() would be handled by manage.py. os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'myproject.settings') if not settings.configured: settings.configure( INSTALLED_APPS=['templated_mail'], TEMPLATES=[ { 'BACKEND': 'django.template.backends.django.DjangoTemplates', 'DIRS': [], 'APP_DIRS': True, # Allows finding templates in app 'templates' subdirectories 'OPTIONS': { 'debug': True, }, }, ], DEFAULT_FROM_EMAIL='noreply@example.com', EMAIL_BACKEND='django.core.mail.backends.console.EmailBackend', # Prints email to console ) # Ensure Django is set up *after* settings are configured. django.setup() # Define your custom email message class. # IMPORTANT: You need to create the actual template file in your Django project. # For example, create 'my_app/templates/emails/welcome.html' with content like: # # {% extends "templated_mail/email.html" %} # {% block subject %}Welcome, {{ user_name }}!{% endblock %} # {% block html %}<p>Hello {{ user_name }},</p><p>Thank you for joining our service!</p>{% endblock %} # {% block plain %}{% block subject %}{% endblock %} Hello {{ user_name }}, Thank you for joining our service!{% endblock %} class WelcomeEmail(BaseEmailMessage): # This path assumes 'emails/welcome.html' is found in one of your TEMPLATES DIRS or APP_DIRS template_name = 'emails/welcome.html' # Instantiate and send the email context_data = {'user_name': 'John Doe'} email = WelcomeEmail(context=context_data) email.send(to=['john.doe@example.com'], from_email='noreply@myservice.com') print("\nEmail sent (output to console). Check your console for details.")
Debug
Known issues
breakingThe `set_context_data` method on `BaseEmailMessage` was renamed to `get_context_data` in version 1.0.0.
fix
Update calls from `email.set_context_data()` to `email.get_context_data()`.
affects: >=1.0.0
breakingThe method `BaseEmailMessage.send_to` was renamed to `BaseEmailMessage.send` in version 0.2.0 for consistency.
fix
Replace all calls to `email.send_to(...)` with `email.send(...)`.
affects: >=0.2.0
breakingSupport for Django 1.10 was removed in version 1.1.0. The library now requires Django 1.11 or higher.
fix
Upgrade your Django project to version 1.11 or a later compatible version (e.g., Django 2.0+).
affects: >=1.1.0
gotchaPrior to version 1.1.1, the `from_email` parameter in `BaseEmailMessage.send` did not always correctly fall back to `settings.DEFAULT_FROM_EMAIL` if omitted.
fix
Upgrade to `django-templated-mail` version 1.1.1 or higher. Alternatively, explicitly pass the `from_email` argument to the `send` method or set it on the `BaseEmailMessage` instance.
affects: <1.1.1
Upgrade
Version history
1.1.1latest on PyPI · released Feb 1, 2018
Audit
Dependencies
DjangorequiredCore framework dependency for templating and email backend.
packagingrequiredUsed for version parsing and compatibility checks.
Agent activity
34 hits · last 30 days
node
32
OpenAI (training)
1
Resources
django-templated-mail — pip install django-templated-mail · libregistry