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 context_processors.py file by themselves, short of importing and decorating them one by one?
Please take a look here: https://github.com/franciscosouza/labs/blob/master/labs/context_processors.py
Just append to your __init__.py (or wherever you defined your application):
as I did here: https://github.com/franciscosouza/labs/blob/master/labs/__init__.py.
You can also use Flask current_app object on your context_processor.py module: http://flask.pocoo.org/docs/api/#flask.current_app.
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.
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.
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.