No project description provided
Project description
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%}
''')
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file jinja-script-block-0.0.4.tar.gz.
File metadata
- Download URL: jinja-script-block-0.0.4.tar.gz
- Upload date:
- Size: 2.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
519aa8051a8250f5c25e3b75a9fa95ee36dac9b8a15ab588f2e2d6341406c2dc
|
|
| MD5 |
a5ea5aec161835df3f00d59284ce9a11
|
|
| BLAKE2b-256 |
ea4add39837f273c948d4f9ee137eec7669b6c06d71d65674583f8e22370edd0
|
File details
Details for the file jinja_script_block-0.0.4-py3-none-any.whl.
File metadata
- Download URL: jinja_script_block-0.0.4-py3-none-any.whl
- Upload date:
- Size: 2.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1a1951c3993524ae646648837a8f2089bc595a6eec5d4e73a2f4f8d2d3f62970
|
|
| MD5 |
672b00b2228b6bbed3196bcf49bf368f
|
|
| BLAKE2b-256 |
c6db12c7066d925568244edd7da63b5e32157b8381cbad25116b3d0b28a07976
|