EMP
EMP

Reputation: 61981

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 one 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?

Upvotes: 2

Views: 709

Answers (2)

heen
heen

Reputation: 21

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

Upvotes: 2

Robert Kluin
Robert Kluin

Reputation: 8292

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

Upvotes: 3

Related Questions