如何将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)
答案 0 :(得分:3)
实际上default_app
和app
是同义词。这应该有效:
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)
您应该可以将其放入文件中并运行。