Template Best Practices
Structure
- Keep page templates in
/www and partials in /www/partials.
- Use includes for repeated sections (
header, footer, cards).
- Keep templates mostly declarative. Prepare complex values in handler context.
- Precompile after boot:
viperhttp.template_warmup("/www")
- Keep templates small and composable.
- Prefer
stream=True for larger pages to avoid large intermediate buffers.
- Keep cacheable routes deterministic and attach route-level
ETag.
Safety
- Default output is escaped. Keep it that way.
- Use
|safe only for trusted, sanitized HTML fragments.
- Keep
strict=True in production unless you explicitly need tolerant mode.
- Do not encode business logic in templates.
Debugging
- Keep debug mode off by default:
viperhttp.template_debug(False)
- Enable temporarily when diagnosing parse/runtime issues:
viperhttp.template_debug(True)
- Disable again after diagnosis.
Load and regression checks
- Run parser vectors and runtime matrix tests after template changes.
- Run host HTTP regression (
tools/host_full_test.py).
- Re-run device template cache regression for leak checks.