Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

settings: add jinja2 support (bug 1873071) #20

Merged
merged 1 commit into from
Jan 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
ruff
black
jinja2
pytest
pytest-django
ruff
uwsgi
15 changes: 15 additions & 0 deletions src/lando/jinja2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
from django.templatetags.static import static
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What else is going to go in this module? Could we just put this in settings.py?

Copy link
Collaborator Author

@zzzeid zzzeid Jan 8, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What else is going to go in this module? Could we just put this in settings.py?

This is the typical way of adding a Jinja environment. Basically all the filters and custom functionality we added (e.g., template_helpers) in the legacy repo will eventually go in here. This doesn't belong in the settings module.

from django.urls import reverse

from jinja2 import Environment


def environment(**options):
env = Environment(**options)
env.globals.update(
{
"static": static,
"url": reverse,
}
)
return env
8 changes: 8 additions & 0 deletions src/lando/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,14 @@
ROOT_URLCONF = "lando.urls"

TEMPLATES = [
{
"BACKEND": "django.template.backends.jinja2.Jinja2",
"DIRS": [],
"APP_DIRS": True,
"OPTIONS": {
"environment": "lando.jinja2.environment"
},
},
{
"BACKEND": "django.template.backends.django.DjangoTemplates",
"DIRS": [],
Expand Down
Loading