我正在构建一个 Pyramid 应用程序,它需要将 map 图 block 提供给 OpenLayers 网络 map 。
TileStache 是一个 WMS 切片服务器,可以提供我需要的切片,我想在我的 Pyramid 应用程序中将其作为 View 访问。
就其本身而言,访问 TileStache 网址 www.exampletilestacheurl.com/LAYERNAME/0/0/0.png 效果很好 - 它会正确返回磁贴。
在 Pyramid 中,我想使用 pyramid.wsgi.wsgiapp 将 TileStache 应用包装为一个 View 。我的目标是访问 www.mypyramidapp.com/tilestache/LAYERNAME/0/0/0.png 会像上面的 TileStache url 示例一样工作。
我将 TileStache 应用包装成一个 View :
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 中的 View 分配了一个路由:
from tilestache import tileserver
config.add_view(tileserver, name='tilestache')
config.add_route('tilestache', '/tilestache')
但是当我访问任何以 www.mypyramidapp.com/tilestache/ 开头的 url 时,它只会返回 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)
注意:我将应用程序创建移动到模块级别,以便在导入时创建它,而不是在每次处理请求时创建。这可能不是您正在寻找的行为,但大多数时候都是。
