django-mjml
raw JSON → 1.5 verified Fri May 01 auth: no python
Django integration for MJML, the responsive email framework. Currently at v1.5, supports Django 6.0 and Python >=3.9. Release cadence is irregular, roughly yearly updates.
pip install django-mjml Common errors
error ModuleNotFoundError: No module named 'django_mjml' ↓
cause django-mjml not installed or INSTALLED_APPS entry is incorrect.
fix
Run 'pip install django-mjml' and add 'django_mjml' (not 'django-mjml') to INSTALLED_APPS.
error TemplateSyntaxError: 'mjml' is not a registered tag library. Must be one of: ... ↓
cause The template tag library is not loaded or the app is not in INSTALLED_APPS.
fix
Add 'django_mjml' to INSTALLED_APPS and use '{% load mjml %}' at the top of your template.
error ConnectionRefusedError: [Errno 61] Connection refused ↓
cause Using MJML_BACKEND_MODE='tcp' but the MJML TCP server is not running.
fix
Ensure the MJML server (from the separate repo) is started, or switch to 'cmd' mode with a locally installed mjml binary.
Warnings
breaking Version 1.0 dropped support for Python 2.7 and Django versions older than 2.2. Also moved MJML TCP-Server to a separate repository. ↓
fix Upgrade to Python >=3.9 and Django >=3.2 (current minimums). If you relied on the bundled TCP server, migrate to https://github.com/danihodovic/mjml-server.
breaking In v1.5, Python 3.6, 3.7, and 3.8 are no longer supported. Also MJML versions older than 4.14.1 have been removed from tests. ↓
fix Ensure your Python version is >=3.9 and your MJML binary is at least 4.14.1.
Imports
- mjml
from django_mjml import mjml
Quickstart
# settings.py
INSTALLED_APPS = [
...
'django_mjml',
]
MJML_BACKEND_MODE = 'cmd' # or 'http' or 'tcp'
MJML_EXEC_CMD = 'mjml' # local node mjml command
# In your template:
{% load mjml %}
{% mjml %}
<mjml>
<mj-body>
<mj-section>
<mj-column>
<mj-text>Hello {{ name }}!</mj-text>
</mj-column>
</mj-section>
</mj-body>
</mjml>
{% endmjml %}