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

TileStache 是一个 WMS 图块服务器,为我需要的图块提供服务,我想将其作为 Pyramid 应用程序中的视图进行访问。

单独访问 TileStache url, www.exampletilestacheurl.com/LAYERNAME/0/0/0.png, ,效果很好 - 它可以正确返回图块。

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

我将 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 的工作原理吗?

有帮助吗?

解决方案

如果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)

笔记:我将应用程序创建移至模块级别,以便在导入时创建它,而不是每次处理请求时创建。这可能不是您正在寻找的行为,但大多数时候都是如此。

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top