带 Bottle 的 MiddleStorm 中间件
如何将 MiddleStorm 中间件与 瓶子? 我按照这个示例,用 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) I收到此错误:
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)
How do you use MiddleStorm middleware with bottle?
I followed this example, replacing SessionMiddleware with MiddleStorm, but I can't get it to work.
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)
I get this error in console:
exceptions.TypeError: __call__() takes exactly 1 argument (3 given)
If I change the line with myapp to:
myapp = MiddleStorm(app(), db)
I get this error on the webpage:
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)
edit: bottle, storm, middlestorm are installed
edit2: if I chane myapp line to myapp = MiddleStorm(dafault_app, db) I get this error:
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: with @zeekay code I still get this error:
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)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
实际上
default_app
和app
是同义词。这应该有效:只需简单测试一下,它似乎对我有用。您可以尝试测试一下吗:
您应该能够将其放入文件中并运行。
Actually
default_app
andapp
are synonymous. This should work:Just testing briefly and it seems to work for me. Can you try testing this:
You should be able to drop it in a file and just run.