sanic/examples/jinja_example.py

18 lines
381 B
Python
Raw Normal View History

2016-12-13 06:18:33 +00:00
## To use this example:
# curl -d '{"name": "John Doe"}' localhost:8000
from sanic import Sanic
2017-04-11 21:34:55 +01:00
from sanic import response
2016-12-13 06:18:33 +00:00
from jinja2 import Template
template = Template('Hello {{ name }}!')
app = Sanic(__name__)
@app.route('/')
async def test(request):
data = request.json
2017-04-11 21:34:55 +01:00
return response.html(template.render(**data))
2016-12-13 06:18:33 +00:00
2017-04-11 21:34:55 +01:00
app.run(host="0.0.0.0", port=8080, debug=True)