Skip to main content

mako template renderer for aiohttp.web (http server for asyncio)

Project description

https://travis-ci.org/aio-libs/aiohttp_mako.svg?branch=master https://coveralls.io/repos/aio-libs/aiohttp_mako/badge.svg

mako template renderer for aiohttp.web based on aiohttp_jinja2. Library has almost same api and support python 3.5 (PEP492) syntax. It is used in aiohttp_debugtoolbar.

Example

import asyncio
import aiohttp_mako
from aiohttp import web


@aiohttp_mako.template('index.html')
async def func(request):
    return {'head': 'aiohttp_mako', 'text': 'Hello World!'}

async 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>"""
    lookup.put_string('index.html', template)

    app.router.add_route('GET', '/', func)

    handler = app.make_handler()
    srv = await 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.3.0.tar.gz (7.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

aiohttp_mako-0.3.0-py3-none-any.whl (3.5 kB view details)

Uploaded Python 3

File details

Details for the file aiohttp-mako-0.3.0.tar.gz.

File metadata

  • Download URL: aiohttp-mako-0.3.0.tar.gz
  • Upload date:
  • Size: 7.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for aiohttp-mako-0.3.0.tar.gz
Algorithm Hash digest
SHA256 aa5a4d7e9d58d38edfa4c5ac4cb890790a254b6b38fe4cfec58978ddf7845727
MD5 696b82349cfd2576d21b809808743388
BLAKE2b-256 a8434baf40ab738c49953c8acb1ddd733262e05422aede714c70cf2cde4659ee

See more details on using hashes here.

File details

Details for the file aiohttp_mako-0.3.0-py3-none-any.whl.

File metadata

File hashes

Hashes for aiohttp_mako-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 5f9b572b72b60b5fc420781e8092e5018a679aabb5a22ccbf974128e584b68e3
MD5 4f664482eb26cb3d3af163322bddc1af
BLAKE2b-256 02886ec4e179fddca78a22ff02b12d0961faaaad7a02e187947e3e3a1b09ae46

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page