django-mjml-templates
A drop-in replacement for Django's template engine that also understands .mjml files.
uv add django-mjml-templates # or pip install
Swap the backend; everything else about TEMPLATES stays as it was. The engine is still
named django (Django takes the default name from the module segment of BACKEND), so
engines["django"] and using="django" keep working.
TEMPLATES = [{
"BACKEND": "mjml_templates.django.DjangoTemplates", # was django.template.backends.django.DjangoTemplates
"APP_DIRS": True,
"OPTIONS": {"context_processors": [...]},
}]
Every other template renders exactly as before. A template whose name ends in .mjml
(or a from_string whose code starts with <mjml) is a Django template first —
{% extends %}, loops, {% url %}, autoescaping — and the MJML that produces is
compiled to email HTML on render.
{# templates/email/welcome.mjml #}
<mjml>
<mj-head><mj-title>Welcome, {{ user.first_name }}</mj-title></mj-head>
<mj-body>
<mj-section><mj-column>
<mj-text>Hi {{ user.first_name }}, thanks for signing up.</mj-text>
<mj-button href="{{ link }}">Get started</mj-button>
</mj-column></mj-section>
</mj-body>
</mjml>
from django.template.loader import get_template
get_template("email/welcome.mjml").render_email({"user": user, "link": link}, to=[user.email]).send()
render_email(context, request=None, *, subject="", **kwargs) returns an unsent
EmailMultiAlternatives with the plain-text body and the HTML alternative attached, so
you can still attach() a file before sending. kwargs go to EmailMultiAlternatives:
to, from_email, bcc, reply_to, headers, and so on.
For the raw pieces, render_email_parts(context, request=None, *, subject="") returns
a (subject, text, html) named tuple. Both are on .mjml templates only:
- subject — as given, else the rendered
<mj-title>, elseValueError. - text —
email/welcome.txtrendered with the same context if it exists, else the HTML run throughhtml2text. - html — the compiled email.
MJML is compiled with mjml-python (the Rust mrml
port), so there is no Node dependency. Plain-text fallback uses html2text.
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file django_mjml_templates-1.0.0.tar.gz.
File metadata
- Download URL: django_mjml_templates-1.0.0.tar.gz
- Upload date:
- Size: 22.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
15d670ab59f5e79376ea0633886fbaf3f4707ceb3db93fb611c4f2c209354676
|
|
| MD5 |
0c4b1e95fb77f785bbe4486a832b7ff4
|
|
| BLAKE2b-256 |
2eb924be5d6339c7dee5d1cfc8f2a20973bc3227b638104b5e79b52a5343f53b
|
Provenance
The following attestation bundles were made for django_mjml_templates-1.0.0.tar.gz:
Publisher:
release.yml on SmileyChris/django-mjml-templates
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
django_mjml_templates-1.0.0.tar.gz -
Subject digest:
15d670ab59f5e79376ea0633886fbaf3f4707ceb3db93fb611c4f2c209354676 - Sigstore transparency entry: 2852429809
- Sigstore integration time:
-
Permalink:
SmileyChris/django-mjml-templates@6f7e2c916fa42a2ebcc7f12e50e0faded4ca277a -
Branch / Tag:
refs/tags/v1.0.0 - Owner: https://github.com/SmileyChris
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@6f7e2c916fa42a2ebcc7f12e50e0faded4ca277a -
Trigger Event:
push
-
Statement type:
File details
Details for the file django_mjml_templates-1.0.0-py3-none-any.whl.
File metadata
- Download URL: django_mjml_templates-1.0.0-py3-none-any.whl
- Upload date:
- Size: 5.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
de196564e2a3a3b888256794258c2416ff7df0d292136c5db0ff31dc63e02ac4
|
|
| MD5 |
9e51c2c9fbcf0454f42da274492af905
|
|
| BLAKE2b-256 |
cf66724eec2964e725a337aedd4fec68dba8b7d6bdfbef6ef6806b2c6ac55934
|
Provenance
The following attestation bundles were made for django_mjml_templates-1.0.0-py3-none-any.whl:
Publisher:
release.yml on SmileyChris/django-mjml-templates
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
django_mjml_templates-1.0.0-py3-none-any.whl -
Subject digest:
de196564e2a3a3b888256794258c2416ff7df0d292136c5db0ff31dc63e02ac4 - Sigstore transparency entry: 2852429869
- Sigstore integration time:
-
Permalink:
SmileyChris/django-mjml-templates@6f7e2c916fa42a2ebcc7f12e50e0faded4ca277a -
Branch / Tag:
refs/tags/v1.0.0 - Owner: https://github.com/SmileyChris
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@6f7e2c916fa42a2ebcc7f12e50e0faded4ca277a -
Trigger Event:
push
-
Statement type: