Skip to main content

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

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

Uploaded Source

Built Distribution

Flask_Htmldoom-0.1.2-py3-none-any.whl (4.0 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: Flask-Htmldoom-0.1.2.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.2.tar.gz
Algorithm Hash digest
SHA256 98b7217a1691652ca4a8de108735ac95cfa51219b41d9d662b2a8502d42674ff
MD5 7220c650744781f31b6934c8ca9109d5
BLAKE2b-256 a66c28a354454daed993972bbf251b8f23ec2d7203a76978a96dc608f4bb6e26

See more details on using hashes here.

File details

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

File metadata

  • Download URL: Flask_Htmldoom-0.1.2-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.32.2 CPython/3.6.5

File hashes

Hashes for Flask_Htmldoom-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 8929dcdd1b5aa6521522d52a19363ea1a7a5c131704b3693cdf2bdb425299078
MD5 77ce1a670d9a9decfa68e46af1fa0ed8
BLAKE2b-256 9fbb73c24b49ec7a95222c10b487b99ae65ba2b23f199a62c32bd2561dfb7f68

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