2013-06-02 105 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)的快速掃描顯示沒有這樣的組刪除。會看起來更進一步,但到目前爲止,它看起來像教程是錯誤的。 –

相關問題