2013-06-02 106 views
0

我有一个web.py应用程序,其中包含以下服务器代码。GET()只需要2个参数(给出4个参数)

import web 
import mod1 

urls = (
    '/(\w*)/(c|r|u|d)/(.*)', '\\1.\\2', 
) 

if __name__ == "__main__": 
    app = web.application(urls, globals()) 
    app.run()   

mod1.py包含

class c: 
    def POST(self): 
     return "C" 

class d: 
    def DELETE(self): 
     return "d" 

class u: 
    def POST(self): 
     return "u" 

class r: 
    def GET(self, _id): 
     return "v={0}".format(_id) 

现在请求http://.../mod1/r/3回报GET() takes exactly 2 arguments (4 given)

这里有什么问题?

回答

4

您的URL配置有参数((\w*)(c|r|u|d)(.*))。加上方法的self参数,这使得4个参数。

调整你的GET方法接受的所有参数:

def GET(self, param1, operation, id_): 

这些比赛的每个正则表达式的捕获组;我猜对每个参数的名称,你可以根据需要进行调整。

+0

但是在[tutorial](http://webpy.org/docs/0.3/tutorial)中,它表示“'1”被第一次捕获正则表达式所取代;任何**剩余的**捕获都会得到传递给你的功能。“ –

+0

[本页](http://webpy.org/cookbook/url_handling)没有提及它,似乎没有关于此的更多信息。坦率地说,我自己并不使用'web.py'。这可能是教程不正确。 :-) –

+1

@GenghisKhan:对[代理码](https://github.com/webpy/webpy/blob/master/web/application.py#L430)的快速扫描显示没有这样的组删除。会看起来更进一步,但到目前为止,它看起来像教程是错误的。 –

相关问题