Skip to content

Instantly share code, notes, and snippets.

@dotpot
Forked from jmvrbanac/app.py
Created January 17, 2017 10:39
Show Gist options
  • Save dotpot/e21abd0dabf7e207c6047658fcf217f8 to your computer and use it in GitHub Desktop.
Save dotpot/e21abd0dabf7e207c6047658fcf217f8 to your computer and use it in GitHub Desktop.
Using Jinja2 with Falcon
import os
import falcon
import jinja2
def load_template(name):
path = os.path.join('templates', name)
with open(os.path.abspath(path), 'r') as fp:
return jinja2.Template(fp.read())
class ThingsResource(object):
def on_get(self, req, resp):
template = load_template('awesome.j2')
resp.status = falcon.HTTP_200
resp.content_type = 'text/html'
resp.body = template.render(something='testing')
app = falcon.API()
things = ThingsResource()
app.add_route('/things', things)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment