带 Bottle 的 MiddleStorm 中间件

发布于 2024-11-24 06:14:51 字数 2226 浏览 1 评论 0原文

如何将 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

流殇 2024-12-01 06:15:46

实际上 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)

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

Actually default_app and app are synonymous. This should work:

myapp = MiddleStorm(app(), db)

Just testing briefly and it seems to work for me. Can you try testing this:

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)

You should be able to drop it in a file and just run.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文