Merge pull request #663 from mmaybeno/fix_jinja_example_typo
Fix typo for jinja example and converted to dir
This commit is contained in:
commit
8d537a6d0b
|
@ -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,9 +20,9 @@ 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)
|
||||||
|
|
||||||
|
|
||||||
app.run(host="0.0.0.0", port=8080, debug=True)
|
app.run(host="0.0.0.0", port=8080, debug=True)
|
8
examples/jinja_example/requirements.txt
Normal file
8
examples/jinja_example/requirements.txt
Normal 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
|
10
examples/jinja_example/templates/example_template.html
Normal file
10
examples/jinja_example/templates/example_template.html
Normal 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>
|
Loading…
Reference in New Issue
Block a user