這是我的代碼:爲什麼我得到一個KeyError?
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()
而且我得到以下錯誤:
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'
晴人們似乎忘記了實際創建類(在我的情況下運行),或在是否將其導入失敗需要。除了檢查這些東西,我沒有找到任何其他解決方案。
哦,我的上帝,你不知道我是怎麼長在我的代碼凝視,我只是不明白:(感謝您的幫助 – RandomDisplayName