Views¶
Zeython renders server-side HTML with Jinja2, by convention reading templates
from resources/views/. A .blade.html file additionally gets a Laravel
Blade-styled directive syntax compiled straight to Jinja2 — see
Blade; this page covers plain Jinja2, which a .blade.html
template can freely @extends/@include alongside (and vice versa). A third
style, .py, builds HTML with plain Python function calls instead of a
template language at all — see Components (Python).
# app/Controllers/page_controller.py
from zeython import Controller
from zeython.views import render
class PageController(Controller):
async def show(self, request):
return render(request, "pages/show.html", {"title": "Hello"})
<!-- resources/views/pages/show.html -->
<!doctype html>
<html>
<head><title>{{ title }}</title></head>
<body><h1>{{ title }}</h1></body>
</html>
Wiring it up¶
render() looks up the application's Views instance from the container, so
register ViewServiceProvider alongside your other providers:
# main.py
from zeython import Application, DatabaseServiceProvider, RouteServiceProvider, ViewServiceProvider
app = Application()
app.register(DatabaseServiceProvider)
app.register(ViewServiceProvider)
app.register(RouteServiceProvider(app, modules=("routes.web",)))
Configuration¶
By default templates are read from <project root>/resources/views. Override
with VIEWS_PATH in .env:
Using the Views object directly¶
render() is sugar over the container-bound Views instance; you can also
resolve and use it directly if you need more control (custom filters, globals):
from zeython import Views
views = app.container.make(Views)
views.environment.filters["shout"] = lambda s: s.upper()
Styling views¶
A fresh project ships a real Tailwind CSS build pipeline for these templates — no Node.js required. See Frontend & CSS.