如何在金字塔内提供wsgi应用程序?

时间:2013-11-07 22:18:50

标签: python pyramid wsgi tilestache

我正在构建一个Pyramid应用程序,需要将地图图块提供给OpenLayers Web地图。

TileStache是​​一个WMS磁贴服务器,它为我需要的磁贴提供服务,我希望在Pyramid应用程序中将其作为视图访问。

单独访问TileStache网址www.exampletilestacheurl.com/LAYERNAME/0/0/0.png,效果很好 - 它会正确返回磁贴。

在Pyramid中,我想使用pyramid.wsgi.wsgiapp将TileStache应用程序包装为视图。我的目标是访问www.mypyramidapp.com/tilestache/LAYERNAME/0/0/0.png就像上面的TileStache网址示例一样。

我将TileStache应用程序包装成一个视图:

from pyramid.wsgi import wsgiapp

@wsgiapp
def tileserver(environ, start_response):
    # Enable TileStache tile server
    import TileStache
    tile_app = TileStache.WSGITileServer('tilestache/tilestache.cfg', autoreload=False)
    return [tile_app]

并在myapp.__init__.main中为视图指定了路线:

from tilestache import tileserver
config.add_view(tileserver, name='tilestache')
config.add_route('tilestache', '/tilestache')

但是当我访问以www.mypyramidapp.com/tilestache/开头的任何网址时,它只会返回IndexError: list index out of range.是否有人熟悉wsgiapp的工作方式?

1 个答案:

答案 0 :(得分:2)

如果tile_app是一个wsgi应用程序,你需要返回调用它的结果......

from pyramid.wsgi import wsgiapp

# Enable TileStache tile server
import TileStache
tile_app = TileStache.WSGITileServer('tilestache/tilestache.cfg', autoreload=False)

@wsgiapp
def tileserver(environ, start_response):

    return tile_app(environ, start_response)

注意:我将应用创建移动到模块级别,以便在导入时创建,而不是每次处理请求时创建。这可能不是你正在寻找的行为,但大部分时间都是如此。