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 = 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.1.tar.gz
(3.3 kB
view details)
Built Distribution
File details
Details for the file Flask-Htmldoom-0.2.1.tar.gz
.
File metadata
- Download URL: Flask-Htmldoom-0.2.1.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 | 59fc078449696b6632510f0da19495e97ba7062ad51b5942458490357bdbea44 |
|
MD5 | cb288a585f73decf891b34538876bb76 |
|
BLAKE2b-256 | aa1d08d8f16570946f17bbd98e35e56153980797d100bfd46185122a07b965ab |
File details
Details for the file Flask_Htmldoom-0.2.1-py3-none-any.whl
.
File metadata
- Download URL: Flask_Htmldoom-0.2.1-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 | bedcda4ff47622c8a8ce44747b1c3446ce41c348e07b7ec0d1b6ed3618a20c46 |
|
MD5 | 6cfc97e44dce3e367061d7e25ed40139 |
|
BLAKE2b-256 | 0ad2440722f21aa5cabcf4c2091a1c6b530e76dbaf741f4e323da293c877994c |