No project description provided
Project description
python-odt-template
[!IMPORTANT] This package currently contains minimal features and is a work-in-progress
Table of Contents
Installation
pip install python-odt-template
Usage
Jinja2
from python_odt_template import ODTTemplate
from python_odt_template.jinja import enable_markdown
from python_odt_template.jinja import get_odt_renderer
from python_odt_template.libreoffice import convert_to_pdf
odt_renderer = get_odt_renderer(media_path="inputs")
with ODTTemplate("inputs/simple_template.odt") as template:
odt_renderer.render(
template,
context={"document": document, "countries": countries},
)
template.pack("simple_template_rendered.odt")
convert_to_pdf("simple_template_rendered.odt", "outputs")
Django
# settings.py
# Add at least one staticfiles dirs, this is what the imgae filter will use to find images
STATICFILES_DIRS = [BASE_DIR / "example" / "static"]
# Add the image filter to the builtins templates config
TEMPLATES = [
{
"BACKEND": "django.template.backends.django.DjangoTemplates",
...
"OPTIONS": {
...
"builtins": ["python_odt_template.django"],
},
},
]
# views.py
from python_odt_template import ODTTemplate
from python_odt_template.django import get_odt_renderer
from python_odt_template.libreoffice import convert_to_pdf
odt_renderer = get_odt_renderer()
def render_odt(request):
with ODTTemplate("template.odt") as template:
odt_renderer.render(
template,
{"image": "writer.png"},
)
template.pack("template_rendered.odt")
convert_to_pdf("template_rendered.odt", "outputs")
return FileResponse(
open("outputs/template_rendered.pdf", "rb"), as_attachment=True, filename="template_rendered.pdf"
)
Alternatives
Credits
Thanks to secretary for the enormous amount of integration work on Jinja2 and ODT.
License
python-odt-template
is distributed under the terms of the MIT license.
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
python_odt_template-0.4.0.tar.gz
(284.9 kB
view details)
Built Distribution
File details
Details for the file python_odt_template-0.4.0.tar.gz
.
File metadata
- Download URL: python_odt_template-0.4.0.tar.gz
- Upload date:
- Size: 284.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: python-httpx/0.27.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 85bc4a8e9860c7eb45b0545954d5b85d1f0cc206ae43154903460d530bd9db0e |
|
MD5 | 02faee86c91dd93c1417426adc375ed5 |
|
BLAKE2b-256 | 699bd467afe508b2c54b220f9144b76cea609442895d5a6769f0e63a7d459bef |
File details
Details for the file python_odt_template-0.4.0-py3-none-any.whl
.
File metadata
- Download URL: python_odt_template-0.4.0-py3-none-any.whl
- Upload date:
- Size: 15.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: python-httpx/0.27.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 60c2f726098f4c6a8318406fd1ec706c5b8a0e520b491dda5fa4687cd4b8962c |
|
MD5 | e06536206850d7c75570f17a016f64d9 |
|
BLAKE2b-256 | df5d08cef8d6b166114ac43283b6b936ea40ec435d39368e1b58acd8b6d6ca58 |