mako template renderer for aiohttp.web (http server for asyncio)
Project description
mako template renderer for aiohttp.web based on aiohttp_jinja2. Library supports almost same api. It is used in aiohttp_debugtoolbar.
Example
import asyncio
import aiohttp_mako
from aiohttp import web
@aiohttp_mako.template('index.html')
def func(request):
return {'head': 'aiohttp_mako', 'text': 'Hello World!'}
@asyncio.coroutine
def init(loop):
app = web.Application(loop=loop)
lookup = aiohttp_mako.setup(app, input_encoding='utf-8',
output_encoding='utf-8',
default_filters=['decode.utf8'])
template = """<html><body><h1>${head}</h1>${text}</body></html>"""
template_bug = """<html><body><h1>${head}</h1>${text}</body></html>"""
lookup.put_string('index.html', template)
lookup.put_string('bug.html', template_bug)
app.router.add_route('GET', '/', func)
handler = app.make_handler()
srv = yield from loop.create_server(handler, '127.0.0.1', 8080)
print("Server started at http://127.0.0.1:8080")
return srv, handler
loop = asyncio.get_event_loop()
srv, handler = loop.run_until_complete(init(loop))
try:
loop.run_forever()
except KeyboardInterrupt:
loop.run_until_complete(handler.finish_connections())
License
aiohttp_mako is offered under the Apache 2 license.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
aiohttp_mako-0.0.1.tar.gz
(7.1 kB
view details)
File details
Details for the file aiohttp_mako-0.0.1.tar.gz.
File metadata
- Download URL: aiohttp_mako-0.0.1.tar.gz
- Upload date:
- Size: 7.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e1042bb6e6847ba2239e55efd077d35a800f4172c348dd205e022198c1b9862c
|
|
| MD5 |
ec082f6674bacb99ee440b0d98f27745
|
|
| BLAKE2b-256 |
b9e649fb7f165ea2101d597b3dec2e097c584de34fc35ade2e7e987b0d1a0f7f
|