URL 中的默认应用程序
如果我创建一个应用程序和一些控制器,默认情况下我将使用以下方式访问它:
http://127.0.0.1/application/controller/function
我想更改 URL 的行为,我可以通过不询问来访问任何控制器应用部分。使用我的示例,我希望能够像这样访问我的应用程序的所有控制器:
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.)
我想做的是消除指示应用程序能够访问我的所有控制器的需要,如下所示:
http:// 127.0.0.1/controller/function1
http:// 127.0.0.1/controller2/function2
http:// 127.0.0.1/controller2/function3 (and etc.)
修改我的routes.py:
# routes.py
default_application = 'application'
default_controller = 'controller'
default_function = 'index'
我可以访问 http://127.0.0.1/ 并且我被重定向到 http://127.0.0.1/controller/index 但如果我尝试访问其他功能,我需要指示应用程序。
我没有找到关于如何配置 paths.py 的很好的参考,我认为我必须更改此文件才能获得我想要的内容。
有人可以帮助我吗?
谢谢!
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!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
本书中解释了 web2py URL 重写功能。请注意,您可以选择较新(且更简单)的基于参数的系统 和替代的基于模式的系统(为更复杂的情况提供了一些额外的灵活性)。在您的情况下,基于参数的系统将是最简单的 - 只需在您的
routes.py
文件中包含以下内容:如果您需要其他帮助,我建议您询问 web2py 邮件列表。
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:If you need additional help, I would recommend asking on the web2py mailing list.