librelist archives

« back to archive

per request hook

per request hook

From:
Jay Baker
Date:
2011-12-22 @ 19:46
Hi all, I'm looking for a hook like before_request, but one that has the
request, i.e. a per request pre-processor. What is the best thing to use
for that?

Thanks in advance.

-- Jay

Re: [flask] per request hook

From:
Armin Ronacher
Date:
2011-12-23 @ 01:01
Hi,

On 12/22/11 8:46 PM, Jay Baker wrote:
> Hi all, I'm looking for a hook like before_request, but one that has the
> request, i.e. a per request pre-processor. What is the best thing to use
> for that?
before_request has access to the request.  However remember that the
request object should be considered immutable for many reasons.

If you want apply deployment specific fixes use a WSGI middleware.


Regards,
Armin

Re: [flask] per request hook

From:
Jay Baker
Date:
2011-12-23 @ 01:52
ah, thanks. Thought I had tried that before and ran into an issue.

In my particular case at the moment, I just need to inspect the request,
for all requests, and redirect if some particular conditions are met. If
this was view specific I would decorate the impacted views, but that is not
practical in this case.

Thanks Armin.

On Thu, Dec 22, 2011 at 7:01 PM, Armin Ronacher <armin.ronacher@active-4.com
> wrote:

> Hi,
>
> On 12/22/11 8:46 PM, Jay Baker wrote:
> > Hi all, I'm looking for a hook like before_request, but one that has the
> > request, i.e. a per request pre-processor. What is the best thing to use
> > for that?
> before_request has access to the request.  However remember that the
> request object should be considered immutable for many reasons.
>
> If you want apply deployment specific fixes use a WSGI middleware.
>
>
> Regards,
> Armin
>