Skip to main content

htmldoom integration for Flask

Project description

Flask-Htmldoom

htmldoom integration for Pyramid

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"),
        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

Find demo and examples here

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.1.tar.gz (3.3 kB view details)

Uploaded Source

Built Distribution

Flask_Htmldoom-0.1.1-py3-none-any.whl (4.1 kB view details)

Uploaded Python 3

File details

Details for the file Flask-Htmldoom-0.1.1.tar.gz.

File metadata

  • Download URL: Flask-Htmldoom-0.1.1.tar.gz
  • Upload date:
  • Size: 3.3 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.32.2 CPython/3.6.5

File hashes

Hashes for Flask-Htmldoom-0.1.1.tar.gz
Algorithm Hash digest
SHA256 e14c9aaa78f2213b196feb029dde32a8695109ccd5cc001fadaa981bb0c4b044
MD5 2ae9974d0abb736a25516afdf0b3e97c
BLAKE2b-256 ef3aa2e745cb3759f799d4d5915bfc6974d4c70feb86165da8c0b2adf56ccf1c

See more details on using hashes here.

File details

Details for the file Flask_Htmldoom-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: Flask_Htmldoom-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 4.1 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.32.2 CPython/3.6.5

File hashes

Hashes for Flask_Htmldoom-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 1e0320bd6cadca442ab8da870c95087a188b481a5c09db5e088121c73665e068
MD5 1f15bbb3cd2cc2ff946599f221d24291
BLAKE2b-256 691b398e55a28f74cb3db209c1106924463fde7664eaaf0f684704d6bfb767fa

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page