该index方法是任何 TurboGears 控制器类的起点。每个网址
localhost:8080localhost:8080/localhost:8080/index
映射到RootController.index()方法。
我如何将localhost:8080and映射localhost:8080/到.index() butlocalhost:8080/index和localhost:8080/index.htmlthe ._lookup()?
该index方法是任何 TurboGears 控制器类的起点。每个网址
localhost:8080 localhost:8080/localhost:8080/index映射到RootController.index()方法。
我如何将localhost:8080and映射localhost:8080/到.index() butlocalhost:8080/index和localhost:8080/index.htmlthe ._lookup()?
不要在控制器中放置任何索引方法,只需使用 _lookup 根据您想要执行的操作返回正确的控制器。
这将为http://localhost:8080和http://localhost:8080/返回“INDEX1”,同时为http://localhost:8080/index和http://localhost:8080/index.html返回“INDEX2”
class IndexController(BaseController):
@expose()
def index(self, *args, **kw):
return 'INDEX2'
class NoPathController(BaseController):
@expose()
def index(self, *args, **kw):
return 'INDEX1'
class RootController(BaseController):
@expose()
def _lookup(self, *remainder, **params):
if not remainder:
return NoPathController(), remainder
return IndexController(), remainder