Skip to content

Django templates vs jinja2 templates #2786

@slifty

Description

@slifty

I'm working on some template modifications for my local instance of Hypha and I'm facing some pain points with the Django template engine, particularly related to whitespace. Django supports use of jinja2 to drive its templating, and I believe jinja2 is a more feature rich template solution than the one Django provides.

Would there be any openness to considering switching to jinja2 as the default templating system in Hypha?

For context: Apparently 8 years ago the Django team basically said they don't want to support their template system / want to move to something like jinja as the default.

An Example of a Limitation

It might be helpful to have the concrete example that inspired the question / idea. We want to send our emails as plain text rather than HTML (or, eventually, in addition to HTML). Unlike jinja, the Django templating engine has no support for managing whitespace in between control commands because it is designed explicitly around the HTML use case, rather than plain text.

For instance, we want:

----------
{% load activity_tags %}
{% if 1 == 1 %}
hello
{% endif %}
----------

to render

----------
hello
----------

but instead it renders

----------


hello

----------

We can get what we need from a user experience perspective using Django, but the template will be unwieldy:

----------
{% load activity_tags %}{% if 1 == 1 %}hello{% endif %}
----------

In jinja we could do:

----------
{%- load activity_tags -%}
{%- if 1 == 1 -%}
hello
{%- endif -%}
----------

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    Status

    Launched

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions