On Sun, Apr 13, 2008 at 7:05 AM, Amit Upadhyay <[EMAIL PROTECTED]> wrote: > I was wondering about the reason that middleware classes were used instead > of decorators to implement middleware functionality. One of the use cases > that lead me into thinking about it is that I was looking for a way to have > middleware apply only to views of one particular app [facebook app for > example]. The MiddlewareNotUsed exception that is used by DebugMiddleware is > very limited, vs if it was a decorator, the decorator would have the view > passed and it could have taken a decision based on the module path of the > view. > > The other use case I thought of was: on my site, there are some background > processes running intermittently, and the load my mysql server, and abt > 20-30 times a day on my site we get an error abt mysql server not > responding. I imagined writing a middleware that will catch this exception, > and sleep for a few secs and then call the view again, but I realized the > current design of middleware does not allow that, and the only way to do > this would be to send a http302 or something, which would be useless for > POST requests and would be dangerous if website is loaded due to some reason > [it will lead to recursive 302, adding up lot of load on the website]. With > middleware I would have passed the actual view, and I would have caught the > exception and in excpetion handler trying to call the view one more time > before giving up.
Call me crazy, but I'm not seeing anything here that can't be done in the process_view() stage of middleware. It receives the incoming request, the view that's about to be executed (so you can get its module path), as well as the arguments that will be applied to it. The code you specified could actually be run inside there, executing the view directly if you like, then returning the response directly from process_view(), bypassing the rest of the middleware phase. It doesn't sound like a pleasant situation to me, but neither does what you're trying to accomplish. I really think you're looking for a middleware that implements process_view(). Look into it,[1] if you haven't already. -Gul [1] http://www.djangoproject.com/documentation/middleware/#process-view --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Django developers" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-developers?hl=en -~----------~----~----~----~------~----~------~--~---
