htmldoom integration for Flask
Project description
Flask-Htmldoom
htmldoom integration for Pyramid
Checkout the live demo
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"),
e.br(),
e.a(href="/jinja2")("jinja2"),
)
)
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,
) -> dict:
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.1.tar.gz
(3.4 kB
view details)
Built Distribution
File details
Details for the file Flask-Htmldoom-0.1.tar.gz
.
File metadata
- Download URL: Flask-Htmldoom-0.1.tar.gz
- Upload date:
- Size: 3.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.6.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | b566966ba33ac8c7f091487806012735089889913ddd253d2d8fe8a724e2afff |
|
MD5 | 8a75eae1c4facc06b3ce2e687649cdc3 |
|
BLAKE2b-256 | 24db7f2654434cf91a48b4de7968487d6170386beea47b2782151f25e3e542d7 |
File details
Details for the file Flask_Htmldoom-0.1-py3-none-any.whl
.
File metadata
- Download URL: Flask_Htmldoom-0.1-py3-none-any.whl
- Upload date:
- Size: 4.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.6.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | f370c0082a9fd7606829fbfaa3346e090e8590df34823527a6f81f0847072328 |
|
MD5 | 1145f9bf0b8aee4c2a3a594c5fea1dd2 |
|
BLAKE2b-256 | b24543a4f054601582e456dd75fe6e376f3f36ea7a4a24cc29867a6df715d210 |