Skip to content

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

License

Notifications You must be signed in to change notification settings

Odya-LLC/flask_html

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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).