Merge pull request #193 from r0fls/jinja-example

add jinja example
This commit is contained in:
Eli Uriegas 2016-12-13 00:30:07 -06:00 committed by GitHub
commit 8fc1462d11

18
examples/jinja_example.py Normal file
View File

@ -0,0 +1,18 @@
## To use this example:
# curl -d '{"name": "John Doe"}' localhost:8000
from sanic import Sanic
from sanic.response import html
from jinja2 import Template
template = Template('Hello {{ name }}!')
app = Sanic(__name__)
@app.route('/')
async def test(request):
data = request.json
return html(template.render(**data))
app.run(host="0.0.0.0", port=8000)