https://github.com/jhb/chameleon_fetcher
A small wrapper for chameleon (page templates) to easily fetch and render templates.
https://github.com/jhb/chameleon_fetcher
Last synced: 3 months ago
JSON representation
A small wrapper for chameleon (page templates) to easily fetch and render templates.
- Host: GitHub
- URL: https://github.com/jhb/chameleon_fetcher
- Owner: jhb
- License: gpl-3.0
- Created: 2022-06-06T10:47:20.000Z (about 3 years ago)
- Default Branch: main
- Last Pushed: 2022-06-13T13:10:14.000Z (almost 3 years ago)
- Last Synced: 2025-02-24T07:58:57.818Z (4 months ago)
- Language: Python
- Size: 20.5 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Chameleon fetcher
A small wrapper for [chameleon page templates](https://github.com/malthe/chameleon) to easily fetch and render templates.
## Installation
```bash
pip install chameleon_fetcher
```## Usage
E.g. you have in template dir `my_template_dir` a file `simple.pt` with
the following content:```html
${template_name} ${myvar} ${some_var}
```You can then do:
```python
from chameleon_fetcher import ChameleonFetchercf = ChameleonFetcher('my_template_dir', some_var=42)
output = cf('simple', myvar='test')
assert output == 'simple test 42'
```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=flaskFor using the actual templates, check the fantastic [chameleon documentation](https://chameleon.readthedocs.io/en/latest/).