Jinja Partials is a Python library designed for the simple reuse of partial HTML page templates within the Jinja template language, particularly for Python web frameworks. It addresses the 'long template problem' by enabling function-like reusability for HTML fragments. The library is currently active, with its latest version being 0.3.1, and shows a consistent release cadence.
pip install jinja-partialsVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to integrate `jinja-partials` with a Flask application. It shows how to register the extension and use the `render_partial` function in your templates. Create an `index.html` and a `partials/greeting.html` inside a `templates` directory, then run the Flask app.
Ensure your project is running on Python 3.10 or newer. Upgrade your Python environment if necessary.
Upgrade to `jinja-partials` version 0.3.1 or newer to resolve issues with asynchronous rendering in async web frameworks.
Review calls to `register_starlette_extensions`. The `app` parameter can now be omitted if not needed for lifecycle management.
Understand that `render_partial()` offers parameter passing and local scope, unlike `{% include '...' %}`. Use `jinja-partials` when you need to pass data specifically to a reusable fragment like a function.Consider using `app.jinja_env.add_extension('jinja_partials.PartialsJinjaExtension')` (for Flask) or adding `"jinja_partials.PartialsJinjaExtension"` to your `extensions` list for standalone Jinja2 environments, especially if you prefer a declarative setup.pip install jinja-partials
For Flask, add `import jinja_partials` and then call `jinja_partials.register_extensions(app)` after initializing your Flask app. For other frameworks, refer to the documentation for the appropriate registration function (e.g., `register_fastapi_extensions`).
Use the correct registration function for your framework, such as `jinja_partials.register_extensions(app)` for Flask, `jinja_partials.register_fastapi_extensions(app, templates)` for FastAPI, `jinja_partials.register_starlette_extensions(templates, app=app)` for Starlette, or `jinja_partials.register_quart_extensions(app)` for Quart.
No dependency data recorded yet.