htmldoom integration for Flask
Project description
Flask-Htmldoom
htmldoom integration for Flask
Checkout the live demo with performance debugging
Usage
Install
pip install Flask-Htmldoom
Plug into Flask
app.py
import os
from flask import Flask
from flask_htmldoom import render_template
app = Flask(__name__)
@app.route("/")
def hello_htmldoom_view():
"""htmldoom rendered view"""
return render_template("templates.hello", data="Hello htmldoom")
if __name__ == "__main__":
app.run("0.0.0.0", int(os.environ.get("PORT", "8080")), debug=True)
templates/hello.py
from htmldoom import elements as e
from htmldoom import renders
from .layout import render_document
@renders(
e.body()(
e.h3()("{contents}"),
e.a(href="/")("Home"),
)
)
def render_body(data):
return {"contents": data["data"]}
def render(data):
return render_document(data, body_renderer=render_body)
templates/layout.py
from htmldoom import base as b
from htmldoom import elements as e
from htmldoom import render as _render
from htmldoom import renders
doctype = _render(b.doctype("html"))
@renders(e.title()("{doctitle}"))
def render_title(doctitle):
return {"doctitle": doctitle}
@renders(e.body()("{content}"))
def render_body(data):
raise NotImplementedError("You are trying to render a layout.")
@renders("{doctype}", e.html()(e.head()("{title}"), "{body}"))
def render_document(
data,
title_renderer=render_title,
body_renderer=render_body,
):
return {
"doctype": doctype,
"title": title_renderer(doctitle=data["data"]),
"body": body_renderer(data=data),
}
def render(data):
return render_document(data=data)
Examples
Deploy examples on heroku:
git push heroku $(git subtree split --prefix examples/2_hackernews master):master
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
Flask-Htmldoom-0.2.0.tar.gz
(3.3 kB
view details)
Built Distribution
File details
Details for the file Flask-Htmldoom-0.2.0.tar.gz
.
File metadata
- Download URL: Flask-Htmldoom-0.2.0.tar.gz
- Upload date:
- Size: 3.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/46.1.3 requests-toolbelt/0.9.1 tqdm/4.45.0 CPython/3.7.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | c141de0e8fd8027d6ed25e027283770285eae2dd45f783216ae686771365146f |
|
MD5 | d5d63b3885aea334068a6819e9dd4b76 |
|
BLAKE2b-256 | 3e69680342c1e66c5e07f010f231ea935f800e6f186c27b3fec4ad501b269d69 |
File details
Details for the file Flask_Htmldoom-0.2.0-py3-none-any.whl
.
File metadata
- Download URL: Flask_Htmldoom-0.2.0-py3-none-any.whl
- Upload date:
- Size: 3.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/46.1.3 requests-toolbelt/0.9.1 tqdm/4.45.0 CPython/3.7.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 39200810e0e35457d1dfafc12eaa3f8d774e4b068ac2a92ca06b3937cef1e836 |
|
MD5 | 7d9fa8e316c7ad8fe507891c647e4c46 |
|
BLAKE2b-256 | 91390eddbf840ca785ae0ab0429d8b573a04fc0738e6adacedb887dfd8e3fe84 |