Skip to main content

Use MJML in Django templates

Project description

test pypi

Django + MJML


The simplest way to use MJML in Django templates.



  • Django from 2.2 to 5.0

  • requests from 2.24.0 (only if you are going to use API HTTP-server for rendering)

  • mjml from 3.6.3 to 4.14.1

1. Install mjml.

Follow and to get more info.

2. Install django-mjml.

$ pip install django-mjml

If you want to use API HTTP-server you also need requests (at least version 2.24):

$ pip install django-mjml[requests]

To install development version use git+ instead django-mjml.

3. Set up in your django project.



Load mjml in your django template and use mjml tag that will compile MJML to HTML:

{% load mjml %}

{% mjml %}
                    <mj-text>Hello world!</mj-text>
{% endmjml %}

Advanced settings

There are three backend modes for compiling: cmd, tcpserver and httpserver.

cmd mode

This mode is very simple, slow and used by default.

Configure your Django:

MJML_EXEC_CMD = 'mjml'

You can change MJML_EXEC_CMD and set path to executable mjml file, for example:

MJML_EXEC_CMD = '/home/user/node_modules/.bin/mjml'

Also you can pass addition cmd arguments, for example:

MJML_EXEC_CMD = ['node_modules/.bin/mjml', '--config.minify', 'true', '--config.validationLevel', 'strict']

Once you have a working installation, you can skip the sanity check on startup to speed things up:


tcpserver mode

This mode is faster than cmd but it needs the MJML TCP-Server.

Configure your Django:

MJML_BACKEND_MODE = 'tcpserver'
    ('', 28101),  # the host and port of MJML TCP-Server

You can set several servers and a random one will be used:

    ('', 28101),
    ('', 28102),
    ('', 28103),

httpserver mode

don’t forget to install requests to use this mode.

This mode is faster than cmd and a bit slower than tcpserver, but you can use official MJML API or run your own HTTP-server (for example to render templates.

Configure your Django:

MJML_BACKEND_MODE = 'httpserver'
        'URL': '',  # official MJML API
        'HTTP_AUTH': ('<Application ID>', '<Secret Key>'),
        'URL': '',  # your own HTTP-server

You can set one or more servers and a random one will be used.

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

django-mjml-1.2.tar.gz (8.3 kB view hashes)

Uploaded source

Built Distribution

django_mjml-1.2-py3-none-any.whl (7.8 kB view hashes)

Uploaded py3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page