展示HN:Pyfrontkit 更新

1作者: Edybrown大约 1 个月前原帖
从Python生成前端通常比必要的复杂,特别是在将设计与后端逻辑集成时。Pyfrontkit(v1.1.10)是一个旨在减少这种摩擦的Python库。它的设计理念基于三个原则:简单、高效和可控。 使用Pyfrontkit,前端的定义所需的代码量显著少于传统的HTML + CSS。在许多情况下,减少的字符数超过50%,从而减少了噪音和潜在的错误点。单一的设计定义可以根据上下文生成不同的输出,包括: - 写入磁盘的HTML + CSS - 内存生成 - 嵌入或分离的样式 所有这些都来自同一个源。模板不是被动的文件,而是Python函数。它们被封装一次,并可以重复使用,而无需创建多个变体。由于模板是函数,它们可以接收包含以下内容的参数: - 数据(内容) - 设计值(颜色、样式、视觉行为) 这使得同一个模板可以动态适应,而无需重复代码。使用模板不会引入额外的摩擦:它可以像任何常规的Python函数一样从后端逻辑中调用,使得与Python框架的集成变得简单明了。最终结果是一个更简单的工作流程,层次更少,学习的概念更少,开发者的控制力更强。 分享一些带有视觉示例的图像,展示该版本的流程。 链接: GitHub: [https://github.com/Edybrown/Pyfrontkit](https://github.com/Edybrown/Pyfrontkit) PyPI: [https://pypi.org/project/pyfrontkit/](https://pypi.org/project/pyfrontkit/)
查看原文
Generating frontend from Python often involves more complexity than necessary, especially when integrating design with backend logic. Pyfrontkit (v1.1.10) is a Python library designed to reduce that friction. Its approach is based on three ideas: simplicity, efficiency and control. With Pyfrontkit, frontend is defined with significantly less code than traditional HTML + CSS. In many cases, the reduction exceeds 50% in written characters, reducing noise and potential error points. A single design definition can produce different outputs depending on the context: HTML + CSS written to disk In-memory generation Embedded or separated styles All from the same source. Templates are not passive files, but Python functions. They are encapsulated once and reused without creating multiple variants. Since templates are functions, they can receive arguments containing: data (content) design values (colors, styles, visual behavior) This allows the same template to adapt dynamically without duplicating code. Using a template introduces no additional friction: it is called like any regular Python function from backend logic, making integration with Python frameworks straightforward. The result is a simpler workflow with fewer layers, fewer concepts to learn and more control for the developer. Sharing a few img with visual examples of the flow in this version<p>Links: GitHub: <a href="https:&#x2F;&#x2F;github.com&#x2F;Edybrown&#x2F;Pyfrontkit" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;Edybrown&#x2F;Pyfrontkit</a> PyPI: <a href="https:&#x2F;&#x2F;pypi.org&#x2F;project&#x2F;pyfrontkit&#x2F;" rel="nofollow">https:&#x2F;&#x2F;pypi.org&#x2F;project&#x2F;pyfrontkit&#x2F;</a>