如何在Pylons中设置默认页面?
我创建了一个新的Pylons应用程序,并添加了一个控制器("main.py")和一个模板("index.mako")。现在,访问网址 http://myserver/main/index
是可以正常工作的。可是我想把这个页面设为默认页面,也就是当我访问 http://myserver/
时,能直接看到这个页面,应该怎么做呢?
我已经在routing.py里添加了一个默认路由:
def make_map():
"""Create, configure and return the routes Mapper"""
map = Mapper(directory=config['pylons.paths']['controllers'],
always_scan=config['debug'])
map.minimization = False
# The ErrorController route (handles 404/500 error pages); it should
# likely stay at the top, ensuring it can always be resolved
map.connect('/error/{action}', controller='error')
map.connect('/error/{action}/{id}', controller='error')
# CUSTOM ROUTES HERE
map.connect('', controller='main', action='index')
map.connect('/{controller}/{action}')
map.connect('/{controller}/{action}/{id}')
return map
我还按照一个回答的建议,删除了 public
目录里的内容(除了favicon.ico),这个回答是关于默认路由不工作的。现在我访问的时候只会出现404错误。
我还需要做些什么,才能让这个基本功能正常工作呢?
2 个回答
2
你需要删除 public/index.html 这个文件,这样 / 的路由规则才能正常工作。否则,它会直接被提供出来。
3
试试这个:map.connect('/', controller='main', action='index')