Skip to content

Instantly share code, notes, and snippets.

@fdenzer
Forked from jmvrbanac/app.py
Created September 18, 2020 21:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fdenzer/c75e61d520462c91ed3834cbdf04e1ec to your computer and use it in GitHub Desktop.
Save fdenzer/c75e61d520462c91ed3834cbdf04e1ec 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