Merge pull request #663 from mmaybeno/fix_jinja_example_typo

Fix typo for jinja example and converted to dir
This commit is contained in:
Raphael Deem 2017-04-25 20:29:12 -07:00 committed by GitHub
commit 8d537a6d0b
3 changed files with 26 additions and 7 deletions

View File

@ -1,15 +1,16 @@
# Render templates in a Flask like way from a "template" directory in the project # Render templates in a Flask like way from a "template" directory in
# the project
from sanic import Sanic from sanic import Sanic
from sanic import response from sanic import response
from jinja2 import Evironment, PackageLoader, select_autoescape from jinja2 import Environment, PackageLoader, select_autoescape
app = Sanic(__name__) app = Sanic(__name__)
# Load the template environment with async support # Load the template environment with async support
template_env = Environment( template_env = Environment(
loader=jinja2.PackageLoader('yourapplication', 'templates'), loader=PackageLoader('jinja_example', 'templates'),
autoescape=jinja2.select_autoescape(['html', 'xml']), autoescape=select_autoescape(['html', 'xml']),
enable_async=True enable_async=True
) )
@ -19,8 +20,8 @@ template = template_env.get_template("example_template.html")
@app.route('/') @app.route('/')
async def test(request): async def test(request):
data = request.json rendered_template = await template.render_async(
rendered_template = await template.render_async(**data) knights='that say nih; asynchronously')
return response.html(rendered_template) return response.html(rendered_template)

View File

@ -0,0 +1,8 @@
aiofiles==0.3.1
httptools==0.0.9
Jinja2==2.9.6
MarkupSafe==1.0
sanic==0.5.2
ujson==1.35
uvloop==0.8.0
websockets==3.3

View File

@ -0,0 +1,10 @@
<!DOCTYPE html>
<html lang="en">
<head>
<title>My Webpage</title>
</head>
<body>
<h1>Hello World</h1>
<p>knights - {{ knights }}</p>
</body>
</html>