Eclectic Media Git eclecticmedia.space / ed3f198
Added initial python flask boilerplate Ariana Giroux a month ago
2 changed file(s) with 35 addition(s) and 0 deletion(s). Raw diff Collapse all Expand all
0 import os
1
2 from flask import Flask, abort, Response
3 from jinja2 import Environment, FileSystemLoader
4
5
6 app = Flask(__name__)
7
8
9 def render(path, context={}, **kwargs):
10 """ Automatically locates and arranges templates, returning the fully
11 compiled and valid HTML.
12
13 :path: valid path as string
14 :context: a dict of data for the templates
15 :**kwargs: pass kwargs to jinja2.Environment.get_template().render
16 :returns: Compiled HTML. """
17 file_loader = FileSystemLoader('templates') # specify parent dir of tempaltes
18 env = Environment(loader=file_loader) # jinja2 boilerplate
19 template = env.get_template(path) # get templates from template path
20 output = template.render(context, **kwargs) # render the templates, passing context
21 return output
22
23
24 @app.route('/', methods=['GET'])
25 def index():
26 return render('index.jinja', context={})
27
28
29 if __name__ == '__main__':
30 app.run()
0 flask
1 markdown
2 jinja2
3 pystache