python - 带 Bottle 的 MiddleStorm 中间件

标签 python wsgi bottle

如何使用MiddleStorm中间件 bottle ? 我关注了this example ,用 MiddleStorm 替换 SessionMiddleware,但我无法让它工作。

from bottle import *
from storm.locals import *
from middlestorm import MiddleStorm

#other bottle code like this here...
@get('/')
   def index():
   return 'index'

db = create_database("mysql://user:pass@localhost/mydb")
myapp = MiddleStorm(app, db)
run(app=myapp, reloader=True, host='0.0.0.0', port=4321)

我在控制台中收到此错误:

exceptions.TypeError: __call__() takes exactly 1 argument (3 given)

如果我将 myapp 的行更改为:

myapp = MiddleStorm(app(), db)

我在网页上收到此错误:

Traceback (most recent call last):
  File "/usr/local/lib/python2.7/dist-packages/bottle-0.9.5-py2.7.egg/bottle.py", line 651, in _handle
    return callback(**args)
  File "/usr/local/lib/python2.7/dist-packages/bottle-0.9.5-py2.7.egg/bottle.py", line 1143, in wrapper
    rv = callback(*a, **ka)
TypeError: decorator() takes exactly 1 argument (0 given)

编辑:安装了 Bottle、storm、middlestorm

edit2:如果我将 myapp 行更改为 myapp = MiddleStorm(dafault_app, db) 我收到此错误:

Traceback (most recent call last):
  File "/usr/lib/python2.7/wsgiref/handlers.py", line 85, in run
self.result = application(self.environ, self.start_response)
  File "/usr/local/lib/python2.7/dist-packages/middlestorm-0.8.1-py2.7.egg/middlestorm.py", line 68, in __call__
    return self._app(environ, start_response)
TypeError: __call__() takes exactly 1 argument (3 given)
homer - - [17/Jul/2011 16:28:42] "GET / HTTP/1.1" 500 59

edit3:使用@zeekay代码我仍然收到此错误:

Traceback (most recent call last):
  File "/usr/local/lib/python2.7/dist-packages/bottle-0.9.5-py2.7.egg/bottle.py", line 651, in _handle
    return callback(**args)
  File "/usr/local/lib/python2.7/dist-packages/bottle-0.9.5-py2.7.egg/bottle.py", line 1143, in wrapper
    rv = callback(*a, **ka)
TypeError: decorator() takes exactly 1 argument (0 given)

最佳答案

实际上default_appapp是同义词。这应该有效:

myapp = MiddleStorm(app(), db)

只是简单测试了一下,它似乎对我有用。你能尝试测试一下吗:

from bottle import *
from storm.locals import *
from middlestorm import MiddleStorm

@get('/')
def index():
   return 'index'

db = create_database("sqlite://test.db")
myapp = MiddleStorm(app(), db)
run(app=myapp, reloader=True, host='0.0.0.0', port=4321)

您应该能够将其放入文件中并运行。

关于python - 带 Bottle 的 MiddleStorm 中间件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6724430/

相关文章:

python - 如何解决linux vim中的 "requires python 2.x support",我的系统中有python 2.6.6

python - 如何使 Django 管理 URL 仅供本地主机访问?

python - 使用 GeventWSGI 和 Nginx 在生产环境中部署 Flask

python - Bottle 中的 DRY 验证?

python - 将 sqlite3.cursor 转换为 int PYTHON

python - 在 XLS 或 CSV 文件中写入具有不同颜色的单元格的一部分

python - flask子函数未产生结果

python - 将对象添加到 SQLAlchemy 关联对象时出现 KeyError

python - Apache 运行静态内容和 Flask 应用程序

python - 类型错误 : 'dict' object is not callable when using request. json()