-
-
Save Dotrox/a5fa93a997bd90b16c5abc216c8938bb to your computer and use it in GitHub Desktop.
Using Jinja2 with Falcon
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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