Communication between apps
TheCoder777 opened this issue · 3 comments
Hello,
I recently tried this project (it's really cool), and now I'm using it for a project of myself.
(I would say I have quite a bit of flask knowledge)
But I found a problem I couldn't solve by myself so far: How can you call a function from outer scope (e.g. from another app or an utils folder for general functions)?
As soon as you import something like e.g. utils (outer scope) in views (inner scope) it crashes on startup with multiple exceptions like [app name].app not found
and a general flask.cli.NoAppException.
I would like to use this for better code organization and make global functions like is_user_logged_in()
(This specifically because I can't use Flask-Security-Too in this project)
What can I do about this?
Thank you for helping me out!
And sorry for the formatting I'm in a hurry for work :(
Edit: I found out I can't even create a util.py file in an app, and the config LOAD_MODULES_EXTENSIONS
does nothing even if I add utils
there.. am I doing something wrong?
So, LOAD_MODULES_EXTENSIONS main purpose is to pre-load stuff into extensions; therefore you might not need to add a "utils" to it, ever.
As far as I'm concerned you can import modules between blueprints even thought it is not advised as it increases coupling and can lead to circular imports and other nasty issues.
A good approach here is to have an app with shared functionality that should depend on no other app (I usually create a "base" app for that) and put things there, like your utils, OR create a lib folder and tweak your python lookup path a bit. Both approaches work fine. Let me know how it goes.
Thank you for your help!
After 2 more hours of trying stuff out I found out my virtualenv was somehow broken (I don't know why a different error was thrown tho).
So the import form different apps is now working :)
But one thing that still bothers me is that I can't get to import the wsgi.app outside a view function (to gain app context access)
Thanks for replying so fast and sorry that I wasn't able to sooner!
So, there should be no need for you to import the wsgi.app instance. Please, take another look Flask's documentation. Application context section. Cheers!