Utility to quickly fetch and render a chameleon template
Project description
Chameleon fetcher
A small wrapper for chameleon page templates to easily fetch and render templates.
Installation
pip install chameleon_fetcher
Usage
E.g. you have in template dir my_template_dir
a file simple.pt
with
the following content:
<test>${template_name} ${myvar} ${some_var}</test>
You can then do:
from chameleon_fetcher import ChameleonFetcher
cf = ChameleonFetcher('my_template_dir', some_var=42)
output = cf('simple', myvar='test')
assert output == '<test>simple test 42</test>'
Please note how some_var
is set "globally", while for the specific template also a
variable myvar
is used.
The following parameters are accepted by ChameleonFetcher:
- template_dir: the directory where the templates are located
And optionally:
- extension: extension of the template files, defaults to '.pt'
- boolean_attributes: what boolean attributes should be supported, defaults to all valid html boolean attributes. See https://meiert.com/en/blog/boolean-attributes-of-html/
- auto_reload: if the templates should be reloaded on change, defaults to True
- **kwargs: other params you want to have available in all templates, e.g. flask=flask
For using the actual templates, check the fantastic chameleon documentation.
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
chameleon-fetcher-0.0.2.tar.gz
(14.9 kB
view hashes)
Built Distribution
Close
Hashes for chameleon_fetcher-0.0.2-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0cf142586e1257e5d37b32eb6ed3ddac1e59f90b0a05ce49aff0bc6f495baf63 |
|
MD5 | 68c4de9811a81358e715b2945fb70de8 |
|
BLAKE2b-256 | a5f77606d8868ea381cab76131201c61f757711c6291b4fb49effec7b3248e0d |