开发者

How do I set a default page in Pylons?

I've created a new Pylons application and added a controller ("main.py") with a template ("index.mako"). Now the URL http://myserver/main/index works. How do I make this the default page, ie. the on开发者_StackOverflow中文版e returned when I browse to http://myserver/ ?

I've already added a default route in 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

I've also deleted the contents of the public directory (except for favicon.ico), following the answer to Default route doesn't work Now I just get error 404.

What else do I need to do to get such a basic thing to work?


Try this: map.connect('/', controller='main', action='index')


You need to remove public/index.html file to make / routing rule work. Otherwise it is served directly.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜