【发布时间】:2012-03-21 00:37:22
【问题描述】:
我似乎无法让这个脚本工作:
import web
web.config.debug=False
urls = (
'/', 'hello',
'/bye/', 'bye')
app = web.application(urls, globals())
session = web.session.Session(app, web.session.DiskStore('sessions'),
initializer={'count': 0})
class hello:
def GET(self):
session.count += 1
return "You visited " + str(session.count) + " pages."
class bye:
def GET(self):
session.kill()
return ("Bye, web!")
if __name__ == "__main__":
app.run()
这是可从 web.py 文档页面获得的代码:http://webpy.org/cookbook/sessions
当我尝试通过转到http://localhost:1234/ 来访问“hello”页面时,应用程序返回一个内部服务器错误。
这是访问此资源时终端的输出:
http://0.0.0.0:1234/
Traceback (most recent call last):
File "/Library/Python/2.6/site-packages/web/application.py", line 237, in process
return self.handle()
File "/Library/Python/2.6/site-packages/web/application.py", line 228, in handle
return self._delegate(fn, self.fvars, args)
File "/Library/Python/2.6/site-packages/web/application.py", line 409, in _delegate
return handle_class(cls)
File "/Library/Python/2.6/site-packages/web/application.py", line 385, in handle_class
return tocall(*args)
File "testing.py", line 15, in GET
session.count += 1
File "/Library/Python/2.6/site-packages/web/session.py", line 69, in __getattr__
return getattr(self._data, name)
AttributeError: 'ThreadedDict' object has no attribute 'count'
127.0.0.1:49207 - - [20/Mar/2012 20:34:01] "HTTP/1.1 GET /" - 500 Internal Server Error
有哪位 web.py 专家可以告诉我这是怎么回事吗?
【问题讨论】:
-
您的代码与 Python 2.7.2 和 web.py 0.36 一样。
-
我也有同样的问题,谁能帮忙?
-
我不知道是否可能是这种情况,但如果您使用的是磁盘存储,那么您的 web.py 代码所在的同一文件夹中应该有一个会话文件夹。它应该是可写的。