Re: [flask] Custom Application Exceptions with Application Factory and Modules
- From:
- JimG
- Date:
- 2010-05-30 @ 20:38
Great thanks, I've been playing round with this.
A related thought - I have a @before_request decorator which looks up the
full user obj. from the DB and stuffs it in 'g'.
At the moment I am copy pasting this function into each module which needs
to use it.
Part of me wants to think there should be some "base" module or root app
which all the other modules inherit from.
This could define the exception classes and decorators which are used by
other modules.
Not sure the best way to achieve that - or if it is desirable.
Jim.
On 30 May 2010 15:13, Simon Sapin <simon.sapin@exyr.org> wrote:
> Le 30/05/2010 14:45, Simon Sapin a écrit :
> > Le 30/05/2010 14:25, JimG a écrit :
> >
> >> Probably a little bit of a dim question.
> >>
> >> The module object doesn't seem to have the necessary 'error_handler'
> >> function.
> >>
> >> And when using the Application Factory pattern with Modules, there is
> >> no "base" app to set this up on.
> >>
> >> Probably I'm missing something here.
> >>
> >> Many thanks, Jim.
> >>
> > Hi,
> >
> > I think this is easy to add. I’m working on it, I will push it to github
> > when it’s done.
> >
>
> Here it is : http://github.com/Eftarjin/flask
> There is Module.errorhandler for requests in that module, and
> Module.app_errorhandler for all requests. (ie. same as Flask.errorhandler)
> If both handler are available for a given error code, the
> module-specific one is used.
>
> --
> Simon Sapin
>
Re: [flask] Custom Application Exceptions with Application Factory and Modules
- From:
- Simon Sapin
- Date:
- 2010-05-30 @ 21:54
Le 30/05/2010 22:38, JimG a écrit :
> A related thought - I have a @before_request decorator which looks up
> the full user obj. from the DB and stuffs it in 'g'.
>
> At the moment I am copy pasting this function into each module which
> needs to use it.
For this as well as for your error handler, you can define it somewhere
and register it inside you application factory. Or you could make a
subclass of Flask that registers it in __init__.
--
Simon Sapin