django-template-engines
Description
Additional template engines for Django.
Generate :
- PDF (with weasyprint)
- ODT (beta)
- DOCX (alpha)
Requirements
- Weasyprint has specific requirements https://weasyprint.readthedocs.io/en/stable/install.html
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',
],
},
},
]