Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/cenkalti/pyhtml
HTML generation library for Python
https://github.com/cenkalti/pyhtml
Last synced: 8 days ago
JSON representation
HTML generation library for Python
- Host: GitHub
- URL: https://github.com/cenkalti/pyhtml
- Owner: cenkalti
- License: other
- Created: 2012-12-08T11:11:01.000Z (about 12 years ago)
- Default Branch: master
- Last Pushed: 2024-02-08T22:18:53.000Z (almost 1 year ago)
- Last Synced: 2025-01-24T10:06:41.912Z (15 days ago)
- Language: Python
- Homepage:
- Size: 118 KB
- Stars: 72
- Watchers: 4
- Forks: 10
- Open Issues: 0
-
Metadata Files:
- Readme: README.rst
- License: LICENSE
Awesome Lists containing this project
- awesome-python-html - cenkalti/pyhtml
README
PyHTML
======.. image:: https://coveralls.io/repos/github/cenkalti/pyhtml/badge.svg?branch=master
:target: https://coveralls.io/github/cenkalti/pyhtml?branch=masterPyHTML is a simple HTML generation library for Python.
Inspired by `Flask-HTMLBuilder `_
and `this gist `_.Features
--------* Compatible with Python 2 and 3
* Outputs beautifully indented code
* Some tags have sensible defaults
* Have Blocks for filling them laterInstalling
----------.. code-block:: bash
$ pip install pyhtml
Documentation
-------------See the docstring on pyhtml.py file.
Example
-------.. code-block:: python
from pyhtml import *
def f_links(ctx):
for title, page in [('Home', '/home.html'),
('Login', '/login.html')]:
yield li(a(href=page)(title))t = html(
head(
title('Awesome website'),
script(src="http://path.to/script.js")
),
body(
header(
img(src='/path/to/logo.png'),
nav(
ul(f_links)
)
),
div(
lambda ctx: "Hello %s" % ctx.get('user', 'Guest'),
'Content here'
),
footer(
hr,
'Copyright 2013'
)
)
)print(t.render(user='Cenk'))
The above code is rendered as:
.. code-block:: html
Awesome website
![]()
Hello Cenk
Content here
Copyright 2013
Related projects
----------------
* https://github.com/COMP1010UNSW/pyhtml-enhanced