0

The index method is the start point of any TurboGears controller class. Each of the URLs

  • localhost:8080
  • localhost:8080/
  • localhost:8080/index

is mapped to the RootController.index() method.

How can I map localhost:8080 and localhost:8080/ to the .index() but localhost:8080/index and localhost:8080/index.html to the ._lookup()?

leshiy
  • 1
  • 1
  • Welcome to Stack Overflow! We encourage you to [research your questions](http://stackoverflow.com/questions/how-to-ask). If you've [tried something already](http://whathaveyoutried.com/), please add it to the question - if not, research and attempt your question first, and then come back. –  Sep 28 '12 at 07:02

1 Answers1

0

Don't place any index method inside your controller and just use _lookup returning the right controller depending on what you want to do.

This will return 'INDEX1' for http://localhost:8080 and http://localhost:8080/ while returning 'INDEX2' for http://localhost:8080/index and http://localhost:8080/index.html

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
amol
  • 1,609
  • 1
  • 10
  • 15