GET()只需要2个参数(给出4个参数)

Gen*_*han 0 python rest web.py

我有一个带有以下服务器代码的web.py应用程序.

import web
import mod1

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

if __name__ == "__main__": 
    app = web.application(urls, globals())
    app.run()        
Run Code Online (Sandbox Code Playgroud)

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)
Run Code Online (Sandbox Code Playgroud)

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

这里有什么问题?

Mar*_*ers 5

您的URL配置有3个参数((\w*),(c|r|u|d)(.*)).加上self方法的论证,它产生了4个参数.

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

def GET(self, param1, operation, id_):
Run Code Online (Sandbox Code Playgroud)

这些匹配每个正则表达式捕获组; 我猜到了每个参数的名称,你可以根据需要进行调整.