为什么我会得到KeyError?

Ran*_*ame 0 python web.py

这是我的代码:

import web
import json

urls = (
    '/', 'index'
    '/runs', 'runs'
)
app = web.application(urls, globals())
class index:
    def GET(self):
        render = web.template.render('templates/')
        return render.index()

class runs:
    def GET(self):
        return "Test"

if __name__ == "__main__": app.run()
Run Code Online (Sandbox Code Playgroud)

我收到以下错误:

Traceback (most recent call last):
File "/usr/local/lib/python2.7/dist-packages/web/application.py", line 239, in process
return self.handle()
File "/usr/local/lib/python2.7/dist-packages/web/application.py", line 230, in handle
return self._delegate(fn, self.fvars, args)
File "/usr/local/lib/python2.7/dist-packages/web/application.py", line 419, in _delegate
cls = fvars[f]
KeyError: u'index/runs'
Run Code Online (Sandbox Code Playgroud)

大多数人似乎忘记实际创建类(在我的情况下运行)或如果需要导入它失败.除了检查这些东西,我没有找到任何其他解决方案.

Mar*_*ers 5

你忘了逗号:

urls = (
    '/', 'index'
#               ^
    '/runs', 'runs'
)
Run Code Online (Sandbox Code Playgroud)

如果没有逗号,Python会连接两个连续的字符串,所以你真的注册了:

urls = (
    '/', 'index/runs', 'runs'
)
Run Code Online (Sandbox Code Playgroud)

你的globals()词典中没有这样的功能.

如果我添加逗号你的代码工作.