HTML element objects to use in pure Python server side rendering
Project description
HTML Elements
HTML Elements allows you to write HTML website while staying completely in Python. This will allow you to create SPA-like components, but keep your presentation layer in Python.
Because it is in pure Python, it allows to use all the Python goodies such as functions, linting, type checking.
Check out the complete documentation here
Example
To create this form (made with Bulma)
<form>
<div class="field">
<label class="label">
Name
</label>
<div class="control">
<input class="input" name="name" placeholder="Name" type="text" />
</div>
</div>
<div class="field">
<label class="label">
Email
</label>
<div class="control">
<input class="input" name="email" placeholder="Email" type="email" />
</div>
</div>
<button class="button" type="submit">
Submit
</button>
</form>
You write
from html_elements import elements as e
def Input(type: str, label: str) -> e.BaseHtmlElement:
display = label.title()
return e.Div(
[
e.Label([display], classes=["label"]),
e.Div(
[e.Input(classes=["input"], type=type, placeholder=display, name=label)],
classes=["control"]
)
],
classes=["field"]
)
html = e.Form([
Input("text", "name"),
Input("email", "email"),
e.Button(["Submit"], classes=["button"], type="submit")
])
raw = html.to_html(indent_step=2)
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
html_elements-0.2.1.tar.gz
(11.8 kB
view hashes)
Built Distribution
Close
Hashes for html_elements-0.2.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 33ec27ff2ce3c8eb99b908b31fac44f60b0cc4becb13e922e5af5e94a0a69329 |
|
MD5 | 7dd735c048a29b12d7107df2f872bae9 |
|
BLAKE2b-256 | 2e9deb7d2b6afc75226bdb6cb773a99d8183c6c18824b6186d7c4866e42c0ef9 |