pelme / htpy Goto Github PK
View Code? Open in Web Editor NEWGenerate HTML from Python
Home Page: http://htpy.dev
License: MIT License
Generate HTML from Python
Home Page: http://htpy.dev
License: MIT License
Thanks for this well-designed library. Is there any other way to add inline css than providing the entire css code as a string within the htpy.style
element? If not, are there any plans for adding a similar python-code-based mechanism to build up inline CSS?
Thank you,
Christoph
I'm getting an error in an Python 3.10 environment:
ImportError: cannot import name 'Self' from 'typing' (/Users/pietz/.pyenv/versions/3.10.13/lib/python3.10/typing.py)
This error doesn't appear in Python 3.11. I would really appreciate the Python 3.10 backwards compatibility because that's the latest version Azure Static Web Apps supports.
Hello! I was using htpy with flask and noticed that strings included in an htpy element are auto-escaped by default. This is obviously fine and good, but when trying to insert something like a hardcoded query-string or a script tag that uses &
, I noticed that they get escaped as well. I found a workaround by looking at how markupsafe works (wrapping the script or url in a class that provides an __html__
attr), but it required a bit of digging.
Would it be out of scope to provide an exported safe
"pseudo-tag", which just escapes the auto-escaping?
It is not easy to add multiple children from a loop/list comprehension, we should allow some kind of fragments. Maybe it could work like this:
mydllist = dl[((dt[name], dd[age]) for name, age in persons)]
Currently, I run tests/type checking manually via https://github.com/pelme/htpy/blob/d4677100b595b590426bf6dc12c07c2de7944eec/scripts/test before release.
It would be nice to add pre-commit checks for ruff format/ruff check and github actions workflows for pytest, mypy and pyright. It would also be a good idea to test on differentPython versions(3.10, 3.11 and 3.12).
Hey guys, saw your pip package in an HN thread and it really scratched an itch for me. I've been playing around with it and Tailwind to see if I can build a Python native UI framework.
This script:
import htpy as h
button = h.button(".btn")
submit_input = h.input(".btn", type="submit")
checkbox_input = h.input(".checkbox", type="checkbox")
print(
h.div[
h.p["Hello, World!"],
button(".bottom")["Click me!"],
checkbox_input(name="test"),
submit_input(value="Submit"),
]
)
Outputs: (I'm adding newlines for readability)
<div>
<p>Hello, World!</p>
<button class="bottom">Click me!</button>
<input name="test"><input value="Submit">
</div>
Where as I would have expected successive Element()
calls to accumulate attributes, and intelligently merge accumulated classes, e.g.
<div>
<p>Hello, World!</p>
<button class="btn bottom">Click me!</button>
<input class="checkbox" type="checkbox" name="test">
<input class="btn" type="submit" value="Submit">
</div>
For what its worth, with just one line change I was able to get the attribute accumulation by prepending **self._attrs,
here.
Thoughts? I appreciate this can be worked around with the UI Component pattern you mention, but applying that at such a low level makes composition quite painful. Presumably you would end up almost never being able to use the clever element()[]
syntax since its all wrapped in method calls.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.