0

我在使用 Bottle 应用程序实现 Cork 库时遇到了一些麻烦。我已经尝试设置示例应用程序,并进行了一些小的修改以使其在 WSGI 容器中运行。主要的变化是我改变了这个:

if __name__ == "__main__":
    main()

对此:

application = default_app()

当我使用管理员用户进行身份验证时,我得到以下信息:

Traceback (most recent call last):
  File "/path_to_app/lib/python2.7/bottle-0.11.4-py2.7.egg/bottle.py", line 763, in _handle
    return route.call(**args)
  File "/path_to_app/lib/python2.7/bottle-0.11.4-py2.7.egg/bottle.py", line 1572, in wrapper
    rv = callback(*a, **ka)
  File "/path_to_app/cork-example/simple_webapp.py", line 47, in login
    aaa.login(username, password, success_redirect='/', fail_redirect='/login')
  File "build/bdist.linux-x86_64/egg/cork/cork.py", line 209, in login
    self._setup_cookie(username)
  File "build/bdist.linux-x86_64/egg/cork/cork.py", line 610, in _setup_cookie
    session['username'] = username
TypeError: 'NoneType' object does not support item assignment

当我尝试查看主页时,我收到此错误:

Traceback (most recent call last):
  File "/path_to_app/lib/python2.7/bottle-0.11.4-py2.7.egg/bottle.py", line 763, in _handle
    return route.call(**args)
  File "/path_to_app/lib/python2.7/bottle-0.11.4-py2.7.egg/bottle.py", line 1572, in wrapper
    rv = callback(*a, **ka)
  File "/path_to_app/cork-example/simple_webapp.py", line 90, in index
    aaa.require(fail_redirect='/login')
  File "build/bdist.linux-x86_64/egg/cork/cork.py", line 267, in require
    cu = self.current_user
  File "build/bdist.linux-x86_64/egg/cork/cork.py", line 417, in current_user
    username = session.get('username', None)
AttributeError: 'NoneType' object has no attribute 'get'

我可能会犯一个新手错误吗?还是有其他问题?

4

1 回答 1

0

我想到了。这是一个新手错误。Bottle 文档说,如果你想在文件末尾使用 Bottle 和 mod_wsgi,你应该使用这个:

application = default_app()

在更好地理解了这一切是如何工作的之后,我意识到我向 mod_wsgi 发送了错误的应用程序对象。相反,我应该使用这个:

application = app #app was defined earlier in the example application
于 2013-02-12T00:46:43.710 回答