Context processor use is problematic. #153

skorokithakis opened this Issue Jan 3, 2011 · 6 comments


None yet
5 participants

Implementing Facebook authentication, I need a context processor that will insert a current_user variable to the template context by performing some operations on the cookies/request. Since context processors need the app object for the decorator, they are rather hard to put in another file, and this feels unclean.

Could something be done to enable putting context processors in a file by themselves, short of importing and decorating them one by one?


fsouza commented Jan 3, 2011

Please take a look here:

Just append to your (or wherever you defined your application):

import context_processors

as I did here:

You can also use Flask current_app object on your module:

Ah, thank you. Can we get this bit of info added to the context processor docs? It will help many people, I think.

EDIT: Using current_app doesn't seem to work, however importing app directly works, without the circular import I would have expected.


mitsuhiko commented Jan 3, 2011

current_app only works when a request is active. That's a side effect or how Python works internally which I don't want to hack around.


fsouza commented Jan 3, 2011

Ops, my wrong :)

That's a general question on how to structure bigger apps and split them into files. There are dozens of articles and examples (so called skeletons of the projects) on the subject. There are even some in official Flask docs in the patterns chapter.

So I say we can close this issue.


DasIch commented Jun 20, 2013


DasIch closed this Jun 20, 2013

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment