bottlepy / bottle

bottle.py is a fast and simple micro-framework for python web-applications.
http://bottlepy.org/
MIT License
8.38k stars 1.46k forks source link

Hooks not firing across apps #524

Open damjankuznar opened 11 years ago

damjankuznar commented 11 years ago

I have a master app and several sub-apps that are merged into the master app using the Bottle.merge() method. While the routes work as expected, the hooks before_request and after_request (using the default HooksPlugin that is initialized in Bottle.__init__()) do not fire if the route is handled by a different app. For me, such behaviour is unwanted and I would expect that hooks get fired regardless of the handling app. Therefore, I would propose, that the merge() method would also merge hooks.

jamesbennet commented 11 years ago

Thats odd, they do for me. We mount many apps in our project at https://github.com/nicholasdavidson/pybit, and use a hook decorator for HTTP auth. We are using version from debian squeeze.

damjankuznar commented 11 years ago

Could this be because I'm using version 0.11.6 (stable)? Which version do you use? I will do some more testing and report back. And thanks for the reply.

On Sun, Jul 14, 2013 at 9:58 PM, James Bennet notifications@github.comwrote:

Thats odd, they do for me. We mount many apps in our project at https://github.com/nicholasdavidson/pybit, and use a hook decorator for HTTP auth.

— Reply to this email directly or view it on GitHubhttps://github.com/defnull/bottle/issues/524#issuecomment-20942615 .

1mh0 commented 11 years ago

I've encountered the same issue for 0.11.6. Workaround is to add global hook to every merged application.

However it would be nice for API to work that way:

from views.admin import admin_app
admin_app.hooks.add('before_request', login_required)

app.merge(admin_app)
app.hooks.add('before_request', global_hook)
lucassimon994 commented 10 years ago

I am having the same issue when splitting up my application into multiple folders. In 0.13-dev, you should use

app.add_hook('before_request', hook_function)