简体   繁体   English

web2py URL重写

[英]web2py URL rewrite

I am playing with web2py url rewrite. 我正在玩web2py url重写。 The name of application is py2manager and I want to make it default in web2py via code: 应用程序的名称为py2manager ,我想通过代码将其设置为web2py中的默认值:

# vim py2manager/routes.py:

routers = dict(
    BASE = dict(
        default_application='py2manager',
    )
)

But after web2py restart I can't access this page http://localhost:8000/user/login (which should be the same as old one http://localhost:8000/py2manager/default/user/login and old one works fine). 但是在web2py重新启动后,我无法访问此页面http:// localhost:8000 / user / login (应该与旧版本的http:// localhost:8000 / py2manager / default / user / login相同 ,旧版本可以正常工作精细)。 Ever more I cant find logs for debugging that somehow. 我无法找到用于调试的日志。

My web2py version is 2.14.6-stable+timestamp.2016.05.09.19.18.48 cloned from git. 我的web2py版本是从git克隆的2.14.6-stable+timestamp.2016.05.09.19.18.48

How to make correct rewrite with omitting py2manager/default path. 如何省略py2manager/default路径进行正确的重写。

PS As doc I've used official man http://web2py.com/books/default/chapter/29/04/the-core#URL-rewrite PS作为文档,我曾经使用过官方文件http://web2py.com/books/default/chapter/29/04/the-core#URL-rewrite

The default function is index , so the router needs more information to distinguish between a request for /index/user/login (where user and login are both args of the index function) and /user/login (where login is an arg of the user function). 默认功能是index ,因此路由器需要更多信息来区分对/index/user/login的请求(其中userlogin都是index函数的args)和/user/login (其中loginuser功能)。 To do this, you must specify the list of functions in the relevant controller: 为此,必须在相关控制器中指定功能列表:

routers = dict(
    BASE = dict(
        default_application='py2manager',
    ),
    py2manager = dict(
        default_controller='default',
        default_function='index',
        functions=dict(
            default=['index', 'user', 'list', 'of', 'other', 'functions']
        )
    )
)

Also, if possible, you should use the URL() function to generate your URLs, as it will always produce the appropriate URL for a given route based on the configuration of your router. 另外,如果可能,应该使用URL()函数生成URL,因为它将始终根据路由器的配置为给定路由生成适当的URL。

The routes may need to be reloaded. 路线可能需要重新加载。

If you go to Admin. 如果您转到管理员。 At the top right corner, next to the Change Admin Password button is a Reload Routes button. 在右上角,“更改管理员密码”按钮旁边是“重新加载路由”按钮。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM