後備視圖考慮下面的金字塔應用:定義在遍歷
from pyramid.config import Configurator
class Foo(dict):
pass
def make_root(request):
return {'foo': Foo()}
def foo(request):
return request.subpath
def bar(request):
return {"whoami": "bar", "subpath": request.subpath}
def start(global_config, **settings):
config = Configurator(settings=settings)
config.set_root_factory(make_root)
config.add_view(foo, context=Foo, renderer="json")
config.add_view(bar, name="bar", context=Foo, renderer="json")
return config.make_wsgi_app()
此應用程序使用穿越和響應/foo
和/foo/bar
就好了。我在想,如果,遍歷/foo/booarns
的時候,有一些地方在穿越之前決定返回一個404像一個默認掛鉤,或後備觀點:
config.add_view(any_other, name="*default*", context=Foo, ...)
然後,這一觀點將被調用時路徑的第二個組件尚未綁定到任何其他視圖,但在相同的上下文中,路徑組件仍可用爲request.view_name
和request.subpath
。
確實。它從來沒有發生過,因爲它很好地隱藏在API參考中。非常感謝。 – C2H5OH 2012-07-17 20:35:59