Ejemplo n.º 1
0
def template_view():
    return {'var': uuid.uuid4()}

def show_request(request, path):
    return {
        'method': request.method,
        'path': path,
        'headers': dict(request.headers),
    }

routes = route(
    GET('/', hello, name='hello'),
    GET('/environ', environ, name='environ', renderer='json'),
    GET('/page/{pk:int}', page, name='page'),
    GET('/search', qs(query=opt(str)), search, name='search'),
    GET('/template', template_view, name='template', renderer='template.html'),
    GET('/request/{path:path}', show_request, renderer='json'),
)

env = Environment(loader=PackageLoader('app', 'templates'))
env.globals['reverse'] = routes.reverse


def application(environ, start_response):
    request = Request(environ)

    try:
        trace = routes(request)
        view = trace.target
        args, kwargs = trace.args, trace.kwargs