/django-template-engines

Additional template engines for Django (ODT & PDF)

Primary LanguagePythonMIT LicenseMIT

Build Status Maintainability codecov Python Version Django Version PyPI version Documentation Status

django-template-engines

Description

Additional template engines for Django.

Generate :

  • PDF (with weasyprint)
  • ODT (beta)
  • DOCX (alpha)

Requirements

How to use a specific template backend

In the settings, add:

INSTALLED_APPS = [
    ...
    'template_engines',
]

...
# Put custom engines before DjangoTemplates Engine (Custom engines will search ONLY template ending with .pdf (weasyprint) .odt (odt) and .docx (docx)
TEMPLATES = [
    {
        'BACKEND': 'template_engines.backends.weasyprint.WeasyprintEngine',
        'APP_DIRS': True,
        'DIRS': [
        ],
        'OPTIONS': {
            'context_processors': [
                'django.template.context_processors.debug',
                'django.template.context_processors.request',
                'django.contrib.auth.context_processors.auth',
                'django.contrib.messages.context_processors.messages',
            ],
        },
    },
    {
        'BACKEND': 'template_engines.backends.odt.OdtEngine',
        ...,
    },
    {
        'BACKEND': 'template_engines.backends.docx.DocxEngine',
        ...,
    },
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [
        ],
        'APP_DIRS': True,
        'OPTIONS': {
            'context_processors': [
                'django.template.context_processors.debug',
                'django.template.context_processors.request',
                'django.contrib.auth.context_processors.auth',
                'django.contrib.messages.context_processors.messages',
            ],
        },
    },
]

Documentation

https://django-template-engines.readthedocs.io/