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
Close
Hashes for jinja_script_block-0.0.3-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 43deb6701c638f3f991840af626316d88699d4f805b9f3faf562d1fc5496e7ca |
|
MD5 | a63b569b4c9b71ffddb3892e9c701701 |
|
BLAKE2b-256 | e211f5320f31d3d0c39b552fa59635b8383314dc6af45acf9951d7ecc5f22b13 |