Registry / web-framework / django-jinja

django-jinja

JSON →
library2.11.0pypypiunverified

django-jinja integrates the Jinja2 templating language into Django projects, providing a comprehensive Jinja2 backend for Django's template system. This allows developers to leverage Jinja2's powerful features within their Django applications. The current version is 2.11.0, and the library maintains an active release cycle, regularly updating to support new Django and Python versions.

pip install django-jinja
INSTALL
IMPORT
SIG · DJANGO-JINJA
D
django-jinja
web-frameworkpythonv2.11.0
Install
3.7s avg
Import
Disk
67MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v2.11.0 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.920 runs
installs and imports cleanly · install 0.0s · import 0.000s · 67.8MB
glibc
py 3.103.920 runs
installs and imports cleanly · install 3.7s · import 0.000s · 68MB
67MB installed
● package 67MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

Jinja2 Backend Configuration
TEMPLATES = [ { "BACKEND": "django_jinja.base.Jinja2", ... }, ... ]
TEMPLATES = [ { "BACKEND": "django.template.backends.jinja2.Jinja2", ... }, ... ]
For full django-jinja features and integration, always use 'django_jinja.base.Jinja2' as the backend. 'django.template.backends.jinja2.Jinja2' is Django's built-in, less feature-rich Jinja2 backend.

To quickly set up django-jinja: 1. Add 'django_jinja' and your app 'myapp' to `INSTALLED_APPS`. 2. Configure `TEMPLATES` in `settings.py` to use `django_jinja.base.Jinja2` as a backend, ensuring `match_extension` (e.g., '.jinja') matches your template file names. 3. Create a simple view in `myapp/views.py` that renders a Jinja2 template. 4. Create a Jinja2 template (e.g., `myapp/templates/myapp/hello.jinja`). 5. Map a URL to your view in `project/urls.py`. This minimal setup allows Django to load and render Jinja2 templates via django-jinja.

# settings.py INSTALLED_APPS = [ 'django.contrib.admin', 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.messages', 'django.contrib.staticfiles', 'django_jinja', 'myapp', ] TEMPLATES = [ { "BACKEND": "django_jinja.base.Jinja2", "APP_DIRS": True, "OPTIONS": { "match_extension": ".jinja", "autoescape": True, "context_processors": [ "django.template.context_processors.debug", "django.template.context_processors.request", "django.contrib.auth.context_processors.auth", "django.contrib.messages.context_processors.messages", ], "globals": { "static": "django.templatetags.static.static", "url": "django.urls.reverse", }, "extensions": [ "jinja2.ext.do", "jinja2.ext.loopcontrols", "jinja2.ext.with_", "jinja2.ext.i18n", "jinja2.ext.autoescape", "django_jinja.base.DefaultExtension", ] }, }, { "BACKEND": "django.template.backends.django.DjangoTemplates", "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", ], }, }, ] DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField' # myapp/views.py from django.shortcuts import render def hello_world(request): return render(request, "myapp/hello.jinja", {"name": "World"}) # myapp/templates/myapp/hello.jinja <!DOCTYPE html> <html> <head> <title>Jinja2 in Django</title> </head> <body> <h1>Hello {{ name }}!</h1> <p>This is a Jinja2 template.</p> </body> </html> # project/urls.py from django.contrib import admin from django.urls import path from myapp.views import hello_world urlpatterns = [ path('admin/', admin.site.urls), path('hello/', hello_world, name='hello_world'), ]
Debug
Known issues
breakingVersion 2.11.0 dropped support for Django versions older than 3.2 and Python versions older than 3.8. Projects on older Django/Python will break upon upgrade.
fix
Upgrade your Django project to Django 3.2 or newer, and your Python environment to Python 3.8 or newer. Ensure all project dependencies are compatible.
affects: 2.11.0+
breakingVersion 2.8.0 upgraded to Jinja2 3.0, consequently dropping support for Jinja2 versions 2.11 and below, and also dropped support for Python 3.5.
fix
Upgrade your Jinja2 library to version 3.0 or higher. Ensure your Python environment is 3.6 or higher (preferably 3.8+ for django-jinja 2.11.0+).
affects: 2.8.0+
gotchaPrior to version 2.11.0, the default `NAME` for the Jinja2 template engine backend was 'backend', which could lead to confusion or conflicts if not explicitly overridden.
fix
Explicitly set a unique `"NAME": "jinja2"` (or another descriptive name) within the `Jinja2` backend's dictionary in your `TEMPLATES` settings. Alternatively, upgrade to `django-jinja` 2.11.0+ for a better default.
affects: <2.11.0
gotchaThe `makemessages` command for Jinja2 templates requires correct configuration of Jinja2 i18n extensions and had a specific bug in version 2.7.0 preventing detection of `{% trans %}` tags.
fix
Ensure `jinja2.ext.i18n` is included in the `extensions` list within the `OPTIONS` of your `Jinja2` backend in `TEMPLATES`. For `django-jinja >= 2.9.0`, consider adding `"policies": {"ext.i18n.trimmed": True}`. If on 2.7.0, upgrade to 2.7.1 or newer.
affects: 2.7.0 and generally if i18n not configured
gotchaDjango 3.2 and newer versions require the `DEFAULT_AUTO_FIELD` setting to be explicitly defined in your project's `settings.py` for all models.
fix
Add `DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'` to your `settings.py` file to prevent deprecation warnings and ensure proper primary key types for models.
affects: Django >= 3.2
Upgrade
Version history
2.11.0latest on PyPI · released Sep 3, 2023
Audit
Dependencies
DjangorequiredRequired for integration with the Django framework.
Jinja2requiredThe core templating library that django-jinja integrates.
Agent activity
8 hits · last 30 days
node
8
Resources
django-jinja — pip install django-jinja · libregistry