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 details)
Built Distribution
File details
Details for the file html_elements-0.2.1.tar.gz
.
File metadata
- Download URL: html_elements-0.2.1.tar.gz
- Upload date:
- Size: 11.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.2 CPython/3.10.5 Darwin/23.5.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | d85b97fcadb35c7f388e366dc6564bb5e4572c8f647423a0d55afcdf62d645ce |
|
MD5 | c9adcfa96c37b298e4e260cb3e0be1b2 |
|
BLAKE2b-256 | 24c7eb752c16ef9eeb7c6dd88b1b344e068d319fdbce3cff6becec9750a4b6dc |
File details
Details for the file html_elements-0.2.1-py3-none-any.whl
.
File metadata
- Download URL: html_elements-0.2.1-py3-none-any.whl
- Upload date:
- Size: 12.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.2 CPython/3.10.5 Darwin/23.5.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 33ec27ff2ce3c8eb99b908b31fac44f60b0cc4becb13e922e5af5e94a0a69329 |
|
MD5 | 7dd735c048a29b12d7107df2f872bae9 |
|
BLAKE2b-256 | 2e9deb7d2b6afc75226bdb6cb773a99d8183c6c18824b6186d7c4866e42c0ef9 |