django-mjml


Namedjango-mjml JSON
Version 1.2 PyPI version JSON
download
home_pagehttps://github.com/liminspace/django-mjml
SummaryUse MJML in Django templates
upload_time2024-01-08 16:16:47
maintainer
docs_urlNone
authorIgor Melnyk @liminspace
requires_python>=3.6
licenseMIT
keywords django mjml django-mjml email layout template templatetag
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            .. image:: https://github.com/liminspace/django-mjml/actions/workflows/test.yml/badge.svg?branch=main
 :target: https://github.com/liminspace/django-mjml/actions/workflows/test.yml
 :alt: test

.. image:: https://img.shields.io/pypi/v/django-mjml.svg
 :target: https://pypi.org/project/django-mjml/
 :alt: pypi

|

.. image:: https://cloud.githubusercontent.com/assets/5173158/14615647/5fc03bf8-05af-11e6-8cdd-f87bf432c4a2.png
  :target: #
  :alt: Django + MJML

django-mjml
===========

The simplest way to use `MJML <https://mjml.io/>`_ in `Django <https://www.djangoproject.com/>`_ templates.

|

Installation
------------

Requirements:
^^^^^^^^^^^^^

* ``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 https://github.com/mjmlio/mjml#installation and https://documentation.mjml.io/#installation 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+https://github.com/liminspace/django-mjml.git@main`` instead ``django-mjml``.

**\3\. Set up** ``settings.py`` **in your django project.** ::

  INSTALLED_APPS = (
    ...,
    'mjml',
  )

|

Usage
-----

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

  {% load mjml %}

  {% mjml %}
      <mjml>
          <mj-body>
              <mj-section>
                  <mj-column>
                      <mj-text>Hello world!</mj-text>
                  </mj-column>
              </mj-section>
          </mj-body>
      </mjml>
  {% 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_BACKEND_MODE = 'cmd'
  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::

  MJML_CHECK_CMD_ON_STARTUP = False

tcpserver mode
^^^^^^^^^^^^^^

This mode is faster than ``cmd`` but it needs the `MJML TCP-Server <https://github.com/liminspace/mjml-tcpserver>`_.

Configure your Django::

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

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

  MJML_TCPSERVERS = [
      ('127.0.0.1', 28101),
      ('127.0.0.1', 28102),
      ('127.0.0.1', 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 https://mjml.io/api
or run your own HTTP-server (for example https://github.com/danihodovic/mjml-server) to render templates.

Configure your Django::

  MJML_BACKEND_MODE = 'httpserver'
  MJML_HTTPSERVERS = [
      {
          'URL': 'https://api.mjml.io/v1/render',  # official MJML API
          'HTTP_AUTH': ('<Application ID>', '<Secret Key>'),
      },
      {
          'URL': 'http://127.0.0.1:38101/v1/render',  # your own HTTP-server
      },
  ]

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

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/liminspace/django-mjml",
    "name": "django-mjml",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.6",
    "maintainer_email": "",
    "keywords": "django,mjml,django-mjml,email,layout,template,templatetag",
    "author": "Igor Melnyk @liminspace",
    "author_email": "liminspace@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/ee/62/4537206e8c6f295efc2e98a16cb713304af5c35869996f6b7029dfffa6fe/django-mjml-1.2.tar.gz",
    "platform": "OS Independent",
    "description": ".. image:: https://github.com/liminspace/django-mjml/actions/workflows/test.yml/badge.svg?branch=main\n :target: https://github.com/liminspace/django-mjml/actions/workflows/test.yml\n :alt: test\n\n.. image:: https://img.shields.io/pypi/v/django-mjml.svg\n :target: https://pypi.org/project/django-mjml/\n :alt: pypi\n\n|\n\n.. image:: https://cloud.githubusercontent.com/assets/5173158/14615647/5fc03bf8-05af-11e6-8cdd-f87bf432c4a2.png\n  :target: #\n  :alt: Django + MJML\n\ndjango-mjml\n===========\n\nThe simplest way to use `MJML <https://mjml.io/>`_ in `Django <https://www.djangoproject.com/>`_ templates.\n\n|\n\nInstallation\n------------\n\nRequirements:\n^^^^^^^^^^^^^\n\n* ``Django`` from 2.2 to 5.0\n* ``requests`` from 2.24.0 (only if you are going to use API HTTP-server for rendering)\n* ``mjml`` from 3.6.3 to 4.14.1\n\n**\\1\\. Install** ``mjml``.\n\nFollow https://github.com/mjmlio/mjml#installation and https://documentation.mjml.io/#installation to get more info.\n\n**\\2\\. Install** ``django-mjml``. ::\n\n  $ pip install django-mjml\n\nIf you want to use API HTTP-server you also need ``requests`` (at least version 2.24)::\n\n    $ pip install django-mjml[requests]\n\nTo install development version use ``git+https://github.com/liminspace/django-mjml.git@main`` instead ``django-mjml``.\n\n**\\3\\. Set up** ``settings.py`` **in your django project.** ::\n\n  INSTALLED_APPS = (\n    ...,\n    'mjml',\n  )\n\n|\n\nUsage\n-----\n\nLoad ``mjml`` in your django template and use ``mjml`` tag that will compile MJML to HTML::\n\n  {% load mjml %}\n\n  {% mjml %}\n      <mjml>\n          <mj-body>\n              <mj-section>\n                  <mj-column>\n                      <mj-text>Hello world!</mj-text>\n                  </mj-column>\n              </mj-section>\n          </mj-body>\n      </mjml>\n  {% endmjml %}\n\n|\n\nAdvanced settings\n-----------------\n\nThere are three backend modes for compiling: ``cmd``, ``tcpserver`` and ``httpserver``.\n\ncmd mode\n^^^^^^^^\n\nThis mode is very simple, slow and used by default.\n\nConfigure your Django::\n\n  MJML_BACKEND_MODE = 'cmd'\n  MJML_EXEC_CMD = 'mjml'\n\nYou can change ``MJML_EXEC_CMD`` and set path to executable ``mjml`` file, for example::\n\n  MJML_EXEC_CMD = '/home/user/node_modules/.bin/mjml'\n\nAlso you can pass addition cmd arguments, for example::\n\n  MJML_EXEC_CMD = ['node_modules/.bin/mjml', '--config.minify', 'true', '--config.validationLevel', 'strict']\n\nOnce you have a working installation, you can skip the sanity check on startup to speed things up::\n\n  MJML_CHECK_CMD_ON_STARTUP = False\n\ntcpserver mode\n^^^^^^^^^^^^^^\n\nThis mode is faster than ``cmd`` but it needs the `MJML TCP-Server <https://github.com/liminspace/mjml-tcpserver>`_.\n\nConfigure your Django::\n\n  MJML_BACKEND_MODE = 'tcpserver'\n  MJML_TCPSERVERS = [\n      ('127.0.0.1', 28101),  # the host and port of MJML TCP-Server\n  ]\n\nYou can set several servers and a random one will be used::\n\n  MJML_TCPSERVERS = [\n      ('127.0.0.1', 28101),\n      ('127.0.0.1', 28102),\n      ('127.0.0.1', 28103),\n  ]\n\nhttpserver mode\n^^^^^^^^^^^^^^^\n\n  don't forget to install ``requests`` to use this mode.\n\nThis mode is faster than ``cmd`` and a bit slower than ``tcpserver``, but you can use official MJML API https://mjml.io/api\nor run your own HTTP-server (for example https://github.com/danihodovic/mjml-server) to render templates.\n\nConfigure your Django::\n\n  MJML_BACKEND_MODE = 'httpserver'\n  MJML_HTTPSERVERS = [\n      {\n          'URL': 'https://api.mjml.io/v1/render',  # official MJML API\n          'HTTP_AUTH': ('<Application ID>', '<Secret Key>'),\n      },\n      {\n          'URL': 'http://127.0.0.1:38101/v1/render',  # your own HTTP-server\n      },\n  ]\n\nYou can set one or more servers and a random one will be used.\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Use MJML in Django templates",
    "version": "1.2",
    "project_urls": {
        "Homepage": "https://github.com/liminspace/django-mjml"
    },
    "split_keywords": [
        "django",
        "mjml",
        "django-mjml",
        "email",
        "layout",
        "template",
        "templatetag"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "1f74c2db93ce31915fc0c90d0efe8f8ad569d5fb4c2ebee653005c4045cb108b",
                "md5": "f82d24c6ee7a39fa12978fad964b60ce",
                "sha256": "6ede759763f46f74fb0f9346e9b10d282bb88599c077aaa11939cfb67e3b2845"
            },
            "downloads": -1,
            "filename": "django_mjml-1.2-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "f82d24c6ee7a39fa12978fad964b60ce",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.6",
            "size": 7787,
            "upload_time": "2024-01-08T16:16:45",
            "upload_time_iso_8601": "2024-01-08T16:16:45.500326Z",
            "url": "https://files.pythonhosted.org/packages/1f/74/c2db93ce31915fc0c90d0efe8f8ad569d5fb4c2ebee653005c4045cb108b/django_mjml-1.2-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "ee624537206e8c6f295efc2e98a16cb713304af5c35869996f6b7029dfffa6fe",
                "md5": "b5e400f13091ffef1dd68088464571e3",
                "sha256": "5a8a670614602016bac11470a0499b77c451768af32ed253983c80597bb2f449"
            },
            "downloads": -1,
            "filename": "django-mjml-1.2.tar.gz",
            "has_sig": false,
            "md5_digest": "b5e400f13091ffef1dd68088464571e3",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.6",
            "size": 8288,
            "upload_time": "2024-01-08T16:16:47",
            "upload_time_iso_8601": "2024-01-08T16:16:47.231822Z",
            "url": "https://files.pythonhosted.org/packages/ee/62/4537206e8c6f295efc2e98a16cb713304af5c35869996f6b7029dfffa6fe/django-mjml-1.2.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-01-08 16:16:47",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "liminspace",
    "github_project": "django-mjml",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "requirements": [],
    "lcname": "django-mjml"
}
        
Elapsed time: 0.17876s