Skip to main content

A Django template engine powered by Typst

Project description

Django Typst

A Django template engine that uses Typst to render Portable Document Format (PDF) files.

Full documentation can be found at https://django-typst-engine.readthedocs.io/en/latest/

Installation and Configuration

The Django Typst engine is available from PyPI so you can install it with all the usual tools:

pip install django_typst
# or
uv add django_typst
# or
poetry add django_typst

Once installed, to make the typst engine available, you need to add it to the TEMPLATES configuration in your settings.py. e.g.:

TEMPLATES = [
    ...
    {
        "BACKEND": "django_typst.TypstEngine",
        "NAME": "typst",
        "DIRS": [BASE_DIR / "templates"],
        "APP_DIRS": False,
        "OPTIONS": {
            "ROOT": None,
            "FONT_PATHS": [],
            "IGNORE_SYSTEM_FONTS": False,
            "PDF_STANDARD": "1.7",
            "PPI": None,
        }
    },
]

Note that this should be in addition to the standard Django template engine that was already there.

All the OPTIONS are... optional and the values above represent their defaults should no alternative be provided.

Option Description Default
ROOT The root path to use for relative paths None*
FONT_PATHS Paths to look in for fonts []
IGNORE_SYSTEM_FONTS Only consider fonts in the defined font paths False
PDF_STANDARD PDF revision to target (1.7, a2-b, a3-b) "1.7"
PPI Pixel Per Inch for included PNG None

* The engine with use the folder the template is in as the root if one is not specified.

[!NOTE] The Django Typst Engine does support loading templates from app dirs with the APP_DIR configuration, but just like the jinja2 engine, it expects the in-app folder to have an engine specific name of typst. So if you want to have templates in app directories, please ensure they sit within a folder called typst.

Usage

To use this engine with one of the standard Django class based views you only need to set the template_engine class property to the value "typst". You should also set the content_type property to the value "application/pdf" to ensure the PDF is returned with the correct content type. For example, in a simple TemplateView it would look like this:

from django.views import generic

class MyTemplateView(generic.TemplateView):
  template_engine = "typst"
  content_type = "application/pdf"

  ...

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_typst-0.1.5.tar.gz (5.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

django_typst-0.1.5-py3-none-any.whl (6.9 kB view details)

Uploaded Python 3

File details

Details for the file django_typst-0.1.5.tar.gz.

File metadata

  • Download URL: django_typst-0.1.5.tar.gz
  • Upload date:
  • Size: 5.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for django_typst-0.1.5.tar.gz
Algorithm Hash digest
SHA256 56a972ce230a17b0fea07a711e6d9d590fcfc647c2797a223029716986842d93
MD5 4653a9d7de08835a4c0d995fc5c03e1b
BLAKE2b-256 6e45b08026abbb55ccc4aebf2eeb24c211298d5f8ff42d7ad4a9be29613153aa

See more details on using hashes here.

Provenance

The following attestation bundles were made for django_typst-0.1.5.tar.gz:

Publisher: publish.yml on a-musing-moose/django-typst-engine

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file django_typst-0.1.5-py3-none-any.whl.

File metadata

  • Download URL: django_typst-0.1.5-py3-none-any.whl
  • Upload date:
  • Size: 6.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for django_typst-0.1.5-py3-none-any.whl
Algorithm Hash digest
SHA256 0ed8743c6caa6c499f2cbd4d4e7ec33cdceb0484f0c5644ea785503a9896f0e1
MD5 4088759aa1b7b3707df11c84bac156e7
BLAKE2b-256 484d3292a1d1c2e8c11119351ea994f856a7ccab927ecf8a3405e06dc4d883e8

See more details on using hashes here.

Provenance

The following attestation bundles were made for django_typst-0.1.5-py3-none-any.whl:

Publisher: publish.yml on a-musing-moose/django-typst-engine

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

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