quart-imp/docs/_md/v1/ImpBlueprint-tmpl.md
David Carmichael bfcc49dd8d feat: docs
2024-08-16 15:09:07 +01:00

898 B

Menu = ImpBlueprint/tmpl
Title = ImpBlueprint.tmpl
tmpl(template: str) -> str

Scopes the template lookup to the name of the blueprint (this takes from the __name__ attribute of the Blueprint).

Due to the way Quart templating works, and to avoid template name collisions. It is standard practice to place the name of the Blueprint in the template path, then to place any templates under that folder.

my_blueprint/
├── routes/
│   └── index.py
├── static/...
│
├── templates/
│   └── my_blueprint/
│       └── index.html
│
├── __init__.py

File: my_blueprint/routes/index.py

from quart import render_template

from .. import bp


@bp.route("/")
async def index():
    return await render_template(bp.tmpl("index.html"))

bp.tmpl("index.html") will output "my_blueprint/index.html".