Eclectic Media Git eclecticmedia.space / master app.py
master

Tree @master (Download .tar.gz)

app.py @masterraw · history · blame

import os

from flask import Flask, abort, Response
from jinja2 import Environment, FileSystemLoader


app = Flask(__name__)


def render(path, context={}, **kwargs):
    """ Automatically locates and arranges templates, returning the fully
    compiled and valid HTML.

    :path: valid path as string
    :context: a dict of data for the templates
    :**kwargs: pass kwargs to jinja2.Environment.get_template().render
    :returns: Compiled HTML. """
    file_loader = FileSystemLoader('templates')  # specify parent dir of tempaltes
    env = Environment(loader=file_loader)  # jinja2 boilerplate
    template = env.get_template(path)  # get templates from template path
    output = template.render(context, **kwargs)  # render the templates, passing context
    return output


@app.route('/', methods=['GET'])
def index():
    return render('index.jinja', context={})


if __name__ == '__main__':
    app.run()