Merge branch 'master' of https://github.com/channelcat/sanic
This commit is contained in:
commit
95cfdee8b8
|
@ -9,6 +9,8 @@ On top of being Flask-like, Sanic supports async request handlers. This means y
|
||||||
|
|
||||||
Sanic is developed `on GitHub <https://github.com/channelcat/sanic/>`_. Contributions are welcome!
|
Sanic is developed `on GitHub <https://github.com/channelcat/sanic/>`_. Contributions are welcome!
|
||||||
|
|
||||||
|
If you have a project that utilizes Sanic make sure to comment on the `issue <https://github.com/channelcat/sanic/issues/396>`_ that we use to track those projects!
|
||||||
|
|
||||||
Benchmarks
|
Benchmarks
|
||||||
----------
|
----------
|
||||||
|
|
||||||
|
|
|
@ -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)
|
||||||
|
|
||||||
|
|
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