import asyncio
import aiohttp_debugtoolbar
import aiohttp_jinja2

from aiohttp import web


@aiohttp_jinja2.template('index.html')
def basic_handler(request):
    return {'title': 'example aiohttp_debugtoolbar!',
            'text': 'Hello aiohttp_debugtoolbar!',
            'app': request.app}


@asyncio.coroutine
def exception_handler(request):
    raise NotImplementedError


@asyncio.coroutine
def init(loop):
    # add aiohttp_debugtoolbar middleware to you application
    app = web.Application(loop=loop, middlewares=[aiohttp_debugtoolbar
                          .toolbar_middleware_factory])
    # install aiohttp_debugtoolbar
    aiohttp_debugtoolbar.setup(app)

    # install jinja2 templates
    lookup = aiohttp_jinja2.setup(app, input_encoding='utf-8',
                                  output_encoding='utf-8',
                                  default_filters=['decode.utf8'])
    template = """
    <html>
        <head>
            <title>${title}</title>
        </head>
        <body>
            <h1>${text}</h1>
            <p>
              <a href="${app.router['exc_example'].url()}">
              Exception example</a>
            </p>
        </body>
    </html>
    """
    lookup.put_string('index.html', template)

    app.router.add_route('GET', '/', basic_handler, name='index')
    app.router.add_route('GET', '/exc', exception_handler, name='exc_example')

    handler = app.make_handler()
    srv = yield from loop.create_server(handler, '127.0.0.1', 9000)
    print("Server started at http://127.0.0.1:9000")
    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())

@@ -8,16 +8,30 @@
 asyncio%0A
+import jinja2%0A
 import a
@@ -687,228 +687,8 @@
 p)%0A%0A
-    # install jinja2 templates%0A    lookup = aiohttp_jinja2.setup(app, input_encoding='utf-8',%0A                                  output_encoding='utf-8',%0A                                  default_filters=%5B'decode.utf8'%5D)%0A
     
@@ -751,15 +751,18 @@
 tle%3E
-$
 %7B
+%7B 
 title
+ %7D
 %7D%3C/t
@@ -818,14 +818,17 @@
 %3Ch1%3E
-$
 %7B
+%7B 
 text
+ %7D
 %7D%3C/h
@@ -873,10 +873,11 @@
 ef=%22
-$
 %7B
+%7B 
 app.
@@ -903,16 +903,18 @@
 '%5D.url()
+ %7D
 %7D%22%3E%0A    
@@ -1006,26 +1006,67 @@
     
-lookup.put_string(
+# install jinja2 templates%0A    loader = jinja2.DictLoader(%7B
 'ind
@@ -1073,17 +1073,17 @@
 ex.html'
-,
+:
  templat
@@ -1083,18 +1083,118 @@
 template
+%7D
 )%0A
+    aiohttp_jinja2.setup(app, loader=loader)%0A%0A    # init routes for index page, and page with error
 %0A    app

remove mako temlates from examples/simple.py