Skip to main content

Flask-HTML

Flask GitHub top language LICENCE Odya

HTML generator for Flask applications. Make your HTML code more readable and easier to maintain.

Installation

pip install flask_html

Usage

Simple HTML

from flask_html import Page, Head
from flask_html.core import Style
from flask_html.tags import Body, Div, P
from flask import request
@app.route('/')
def index():
    head = Head('Title', ['link to css'],['link to js'], [{"meta_property": "value"}])
    page = Page(head)
    body = Body(page, styles=Style(color="red", padding_top="15px"),classes=['class1', 'class2'], id='body_id',elements=[
        Div(styles=Style(margin="10px"), classes=['class1', 'class2'], id='div_id', elements=[
            P(styles=Style(color="blue"), classes=['class1', 'class2'], id='p_id', elements=[
                "Hello World"
            ])
        ])
    ])
    return page.render(body, request)

Using with listeners

Note: Jquery automatically injected

opts = [Option('{}'.format(x),'Name {}'.format(x)) for x in range(10)]
sel = Select(opts).on('change', 'let val = $(this).val(); alert(val)')
page = Page(Head('Title', ['link to css'],['link to js'], [{"meta_property": "value"}]))
body = Body(page, elements=[
    sel
])
return page.render(body, request)

Elements

Example of Div elements

"""Div HTML element

Args:
    styles (Style, optional): Inline css styles. Defaults to None.
    classes (List[str], optional): List of class names. Defaults to [].
    id (str, optional): Unique ID. Defaults to None.
    elements (List[object], optional): List of child elements. Defaults to [].
    props (Dict[str, str], optional): Additional tag properties. Defaults to {}.
"""
Div(styles=None, classes=[], id=None, elements=[], props={})

To Do

  • All HTML tags
  • Inline CSS
  • Classes
  • ID
  • Child elements
  • Additional tag properties
  • JS
  • Meta tags
  • Link tags
  • Title
  • Head
  • Body
  • Page
  • Element event listeners
  • DOM manipulation
  • Converting js function to python functions
  • More examples

Contibuting

This package open to contributing. Fork, make changes and open pull request

License

This project is licensed under the MIT License (see the LICENSE file for details).

Release files for Flask-HTML 1.1.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for Flask-HTML 1.1.3
File Size Uploaded
Flask-HTML-1.1.3.tar.gz 9.6 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for Flask-HTML 1.1.3
File Interpreter ABI Platform
Flask_HTML-1.1.3-py3-none-any.whl Python 3 none any Details

Total release size: 18.9 kB

Release files / Flask-HTML-1.1.3.tar.gz

Download URL Flask-HTML-1.1.3.tar.gz
Size 9.6 kB
Tags Source
SHA-256 checksum
How to use checksums
f84dab1472169dde146de7b271cb7f9675f458f0462ecf03dc0c22dbda25bf8e
BLAKE2b-256 checksum
How to use checksums
c0c868d2fd8491d4ddba995d6c9405db7289cdf7a43b4343e24a2d47330f1177
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.10.0

Release files / Flask_HTML-1.1.3-py3-none-any.whl

Download URL Flask_HTML-1.1.3-py3-none-any.whl
Size 9.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
052ed4875203057bc23b4864199b022b792f9efff27f9f411f28acd26b2902ea
BLAKE2b-256 checksum
How to use checksums
fa1723b3e6fbfa5f131afe5077736477a4127eab15e34407853e539ca4643042
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.10.0

Release history Release notifications | RSS feed

This release

1.1.3 This release

2 release files

1.1.2

2 release files

1.1.1

2 release files

1.1.0

2 release files

1.0.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page