global_init()
Initialize the Chameleon template engine for your app.
Usage
global_init(
template_folder,
auto_reload=False,
cache_init=True,
)Call this once at startup, pointing it at the folder that holds your *.pt templates. Template paths used elsewhere (in template(), response(), not_found(), and generic_error()) are resolved relative to this folder. Call it before the modules that define decorated views are imported, so that template name inference sees the right folder.
Examples
from pathlib import Path
import fastapi_chameleontemplates = Path(__file__).resolve().parent / 'templates'
fastapi_chameleon.global_init(templates, auto_reload=dev_mode)
Parameters
template_folder: Union[str, os.PathLike[str]]-
Path to the folder containing your Chameleon templates, as a
stror anyos.PathLikesuch aspathlib.Path. auto_reload: bool = False-
Reload templates from disk when they change. Handy in development; leave
Falsein production. Defaults toFalse. cache_init: bool = True-
When
True(the default), a second call is a no-op once the engine is already initialized. PassFalseto force re-initialization (for example, to switch template folders in tests).
Raises
FastAPIChameleonException-
If
template_folderis empty or is not a directory.