Python 3.12+
pip install ludic[full]
与 Starlette 类似,您还需要安装 ASGI 服务器:
pip install uvicorn
组件.py :
from typing import override<>> from ludic.html import a from ludic.types import Attrs, Component class LinkAttrs(Attrs): to: str class Link(Component[str, LinkAttrs]): @override def render(self) -> a: return a( *self.children, href=self.attrs["to"], style={"color": "#abc"}, )
现在你可以像这样使用它:
link = Link("Hello, World!", to="/home")
网络.py :
from ludic.web import LudicApp from ludic.html import b, p from .components import Link app = LudicApp() @app.get("/") async def homepage() -> p: return p(f"Hello {b("Stranger")}! Click {Link("here", to="https://example.com")}!")
运行应用程序:
uvicorn web:app
更多示例
如需结合框架所有功能的更复杂用法,请访问 GitHub 上 包含示例的文件夹。