Registry / web-framework / jinja-try-catch

jinja-try-catch

JSON →
library0.1.1pypypi✓ verified 79d ago

Jinja2 extension adding {% try %} {% catch %} exception handling blocks. Version 0.1.1, requires Python >=3.7. Low release cadence, maintained as needed.

pip install jinja-try-catch
INSTALL
IMPORT
SIG · JINJA-TRY-CATCH
J
jinja-try-catch
web-frameworkpythonv0.1.1
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

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

TryCatchExtension
from jinja_try_catch import TryCatchExtension
from jinja_try_catch import TryExtension

Instantiate Jinja2 Environment with TryExtension; use {% try %}...{% catch %}...{% endtry %} blocks. Within catch block, `error` variable holds the exception message.

from jinja2 import Environment from jinja_try_catch import TryExtension env = Environment(extensions=[TryExtension()]) template = env.from_string(""" {% try %} {{ 1/0 }} {% catch %} Caught error: {{ error }} {% endtry %} """) print(template.render()) # Output: Caught error: division by zero
Debug
Known issues
gotcha`error` variable is only available inside the {% catch %} block. Referencing it outside will cause an undefined variable error.
fix
Only access `{{ error }}` within the {% catch %} block.
affects: all
deprecatedExtension registered via class name. Future versions may change the API for enabling extensions; check changelog.
fix
Continue using `TryExtension` class; no current deprecation but be aware of potential API changes.
affects: 0.1.x
gotchaCatch block catches all exceptions; no filtering by exception type is supported.
fix
Use conditional logic inside catch block if needed: `{% catch %}{% if 'specific' in error %}...{% endif %}{% endtry %}`.
affects: all
Upgrade
Version history
0.1.1latest on PyPI · released Jun 18, 2023
Audit
Dependencies
Jinja2requiredRequired; the extension works with Jinja2 templates.
Agent activity
10 hits · last 30 days
node
10
Resources