jinja2_registry
jinja2_registry is a convenience library for managing multiple template namespaces with Jinja2
Example
The following Python code sets up a jinja2.Environment and three distinct jinja2.FileSystemLoader objects under a jinja2.PrefixLoader. It then renders a HTML page based on title.html that includes several other files.
from jinja2_registry import Renderer, register_filesystem_loader
register_filesystem_loader('layouts', 'templates/layouts')
register_filesystem_loader('partials', 'templates/partials')
register_filesystem_loader('pages', 'templates/pages')
renderer = Renderer('pages/title.html')
html = renderer.render()
print(html)
The result is rendered from 4 HTML templates, which are located in different directories. In this example, all of the templates are read from the filesystem; however, users may make use of register_loader to attach any standard Jinja2 loader to the registry.
Result
<!DOCTYPE html>
<html>
<head>
<title>new_title</title>
</head>
<body>
<ul>
<li><a href="/content">Content page</a></li>
<li><a href="/title">New title page</a></li>
</ul>
<div>
<p>some_content</p>
</div>
</body>
</html>
The HTML templates are organized into the following structure. Layouts are separated from partials and content. In a production deployment, layouts would likely be stored separately from pages (e.g., in a library), and partials might be automatically generated.
File structure:
templates/
├── layouts
│ └── base.html
├── pages
│ ├── content.html
│ └── title.html
└── partials
└── nav.html
templates/layouts/base.html
<!DOCTYPE html>
<html>
<head>
<title>{% block title %}default_title{% endblock %}</title>
</head>
<body>
{% include "partials/nav.html" %}
<div>
{% block content %}{% endblock %}
</div>
</body>
</html>
templates/partials/nav.html
<ul>
<li><a href="/content">Content page</a></li>
<li><a href="/title">New title page</a></li>
</ul>
templates/pages/content.html
{% extends "layouts/base.html" %}
{% block content %}
<p>some_content</p>
{%- endblock %}
templates/pages/title.html
{% extends "pages/content.html" %}
{% block title %}new_title{% endblock %}
Metadata
Release files for jinja2-registry 0.1.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| jinja2-registry-0.1.1.tar.gz | 5.4 kB | Without provenance | Details for jinja2-registry-0.1.1.tar.gz |
Release files / jinja2-registry-0.1.1.tar.gz
| Download URL | jinja2-registry-0.1.1.tar.gz |
|---|---|
| Size | 5.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
0556bd95e6cd7dfee8e26e426d78409a7b7d4120b2cc3e7fea0bbc3f6717120e
|
|
BLAKE2b-256 checksum How to use checksums |
a20cc216faa4027ebb8f355c3c4f951832ea55817f5cd2ac0ec6c1a7cc109806
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Security for jinja2-registry 0.1.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.