add jinja example
This commit is contained in:
parent
457507d8dc
commit
93b45e9598
18
examples/jinja_example.py
Normal file
18
examples/jinja_example.py
Normal 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)
|
Loading…
Reference in New Issue
Block a user