Skip to main content

HTML templates with just Python

Project description

Travis CI status

HTML templates with just Python.


Use pip to install the package:

pip install stempl


For more examples checkout the tests file.

from flask import Flask
from stempl import *

app = Flask(__name__)

def render_head():
    with Head() as t:
        t << meta(charset='utf-8')
        t << meta(name='viewport', content='width=device-width, initial-scale=1, shrink-to-fit=no')
        t << title('Hello World')
        t << link(href='', rel='stylesheet')
        t << script(src='')
        t << script(src='')
        t << script(src='')

    return t()

def render_navbar():
    with Ul(_class='navbar-nav') as u:
        u << li(a('Home', _class='nav-link', href='#'), _class='nav-item active')
        u << li(a('Features', _class='nav-link', href='#'), _class='nav-item active')
        u << li(a('Pricing', _class='nav-link', href='#'), _class='nav-item active')
        u << li(a('Disabled', _class='nav-link disabled', href='#'), _class='nav-item active')

    with Nav(_class='navbar navbar-expand-lg navbar-light bg-light') as n:
        n << a('Navbar', _class='navbar-brand', href='#')
        with Button(_class='navbar-toggler', type='button', data_toggle='collapse', data_target='#navbarNav') as b:
            b << span(_class='navbar-toggler-icon')
        n << b()
        n << div(u(), _class='collapse navbar-collapse', id='navbarNav')

    return n()

def layout(content):
    with Html() as h:
        h << render_head()
        with Body() as b:
            b << render_navbar()
            b << div(content, _class='container', id='main')
        h << b()

    return doctype() + h()

def index_template():
    with Div(id='index-page') as d:
        d << h1('Hello World')

    return layout(d)

@app.route('/', methods=['GET'])
def index():
    return index_template()

if __name__ == '__main__':'', port=3000, debug=True)

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for stempl, version 1.0.7
Filename, size File type Python version Upload date Hashes
Filename, size stempl-1.0.7.tar.gz (5.8 kB) File type Source Python version None Upload date Hashes View

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Huawei Huawei PSF Sponsor Microsoft Microsoft PSF Sponsor NVIDIA NVIDIA PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page