我正在构建一个金字塔应用程序,它需要服务于OpenLayers网络地图的地图块。
TileStache是一个WMS瓷砖服务器,为我所需要的瓷砖服务,我想在我的金字塔应用程序中作为视图访问它。
就其本身而言,访问TileStache url,www.exampletilestacheurl.com/LAYERNAME/0/0/0.png,工作得很好--它正确地返回了瓷砖。
在金字塔中,我想将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/开头的任何url时,它只返回IndexError: list index out of range.,有人熟悉wsgiapp的工作原理吗?
发布于 2013-11-10 13:38:55
如果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)注意:我将应用程序创建移动到模块级别,以便在导入时创建,而不是每次处理请求时都创建。这可能不是你想要的行为,但大多数时候是这样的。
https://stackoverflow.com/questions/19847850
复制相似问题