def render(response, request): if not response: return if not isinstance(response, dict): # If the response is a function, call it and render the result. if callable(response): return render( response(request, **request.get("route_params", {})), request) response = with_body(response) response["body"] = _render_body(response.get("body"), request) # Default content_type is text/html. if not response.get("headers", {}).get("content_type"): response = with_content_type(response, "text/html") return response
def wrap_not_found(app): return lambda req: app(req) or with_status(with_body("Not Found"), 404)