Jinja2 Script
Introduction
In ERB, custom functions can be written in the template. However with jinja2, the functions should be written in python, and must be included in the rendering environment.
Use Script Block
{% script modulename %}
# Your Python Code that should be in .py
{% endscript %}
Define your python codes in script block. This is compiled before actual run starts.
To use compiled block, do it as following:
{{module.functions_you_defined()}}
{{module.values_you_defined()}}
{{module.function_with_arguments(1)}}
{{module.function_with_arguments_at_render(x)}}
How to use
from jinja_script_block import ScriptBlockExtension
from jinja2 import Environment
env = Environment(extensions=[ScriptBlockExtension])
env.from_string('''
{% script mymodule %}
class MyClass:
containers = []
{% endscript%}
''')
Metadata
Release files for jinja-script-block 0.0.4
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 |
|---|---|---|---|---|
| jinja-script-block-0.0.4.tar.gz | 2.4 kB | Without provenance | Details for jinja-script-block-0.0.4.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| jinja_script_block-0.0.4-py3-none-any.whl | Python 3 | none | any | Details for jinja_script_block-0.0.4-py3-none-any.whl |
Total release size: 4.8 kB
Release files / jinja-script-block-0.0.4.tar.gz
| Download URL | jinja-script-block-0.0.4.tar.gz |
|---|---|
| Size | 2.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
519aa8051a8250f5c25e3b75a9fa95ee36dac9b8a15ab588f2e2d6341406c2dc
|
|
BLAKE2b-256 checksum How to use checksums |
ea4add39837f273c948d4f9ee137eec7669b6c06d71d65674583f8e22370edd0
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.11.1
|
Release files / jinja_script_block-0.0.4-py3-none-any.whl
| Download URL | jinja_script_block-0.0.4-py3-none-any.whl |
|---|---|
| Size | 2.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
1a1951c3993524ae646648837a8f2089bc595a6eec5d4e73a2f4f8d2d3f62970
|
|
BLAKE2b-256 checksum How to use checksums |
c6db12c7066d925568244edd7da63b5e32157b8381cbad25116b3d0b28a07976
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.11.1
|
Security for jinja-script-block 0.0.4
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.