0

This is my code:

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()

And I get the following error:

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'

Mostly people seem to forget to actually create the class (in my case runs) or fail at importing it if needed. I didn't find any other solution than checking these things.

2 Answers2

5

You forgot a comma:

urls = (
    '/', 'index'
#               ^
    '/runs', 'runs'
)

Without the comma, Python concatenates the two consecutive strings, so you really registered:

urls = (
    '/', 'index/runs', 'runs'
)

and you have no such function in your globals() dictionary.

If I add in the comma your code works.

Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343
1

Your code has a typo:

urls = (
    '/', 'index', # missing comma
    '/runs', 'runs'
)
Freek Wiekmeijer
  • 4,556
  • 30
  • 37