开发者

Default application in URL

If I create an application and some controller, by default I will access it using:

http:// 127.0.0.1/application/controller/function

I want to change the behaviour of the URLs that I can access any controller by not asking for the application part. Using my example, I want to be able to access all the controllers of my app like this:

http:// 127.0.0.1 /application/controller/function1  
http:// 127.0.0.1 /application/controller2/function2
http:// 127.0.0.1 /application/controller2/function3  (and etc.)

What I want to do is remove the need to indicate the开发者_运维百科 application to be able to access all my controllers like this:

http:// 127.0.0.1/controller/function1
http:// 127.0.0.1/controller2/function2
http:// 127.0.0.1/controller2/function3  (and etc.)

Modifying my routes.py:

# routes.py
default_application = 'application'
default_controller = 'controller'
default_function = 'index'

I can access http://127.0.0.1/ and I am redirected to http://127.0.0.1/controller/index But If I try to access other function I need to indicate the application.

I didn't find a good reference about how routes.py can be configured, and I think that I have to change this file to get what I want.

Anyone can help me?

Thanks!


The web2py URL rewrite functionality is explained in the book. Note, you have a choice between the newer (and simpler) parameter-based system and an alternative pattern-based system (which provides some additional flexibility for more complex cases). In your case, the parameter-based system would be easiest -- just include the following in your routes.py file:

routers = dict(
    BASE = dict(
        default_application = 'application',
        default_controller = 'controller',
    ),
)

If you need additional help, I would recommend asking on the web2py mailing list.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜