def application(): app = None middleware_list = config(WERKZEUG_MIDDLEWARE) if not middleware_list: raise MiddlewareNotFound for middleware in middleware_list: if app: app = import_string(middleware)(app) else: app = import_string(middleware)() return app
def dispatch_request(self, request): routes = RoutingParser.instance.get_route() adapter = routes.bind_to_environ(request.environ) try: endpoint, values = adapter.match() view, name = endpoint.split(':') view_handler = import_string(view) return view_handler(request, **values) except HTTPException as http_exception: template = WERKZEUG_TEMPLATE_DIR + '/' + \ str(http_exception.code) + '.html' if os.path.exists(template): content = render_to_string( template, description=http_exception.description, code=http_exception.code ) return Response( content, http_exception.code, content_type='text/html') return Response(http_exception.description, http_exception.code)