Modular use of flask-login #739
-
I'm a big proponent of modular code because I think it's easier to design, write, test and maintain. Therefore, I'd like to make modular use of flask-login. That is, I'd like to create a Python module (file) that defines all the generic functions and decorators described in the Usage documentation, have the Flask app factory initialize it with the But I don't see an obvious way to do this because of the interdependencies between the flask-login code and the Flask app factory. I welcome any advice on how to achieve the modularity I want, or an argument that the modularity I want cannot be reasonably achieved. Thanks |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 3 replies
-
Hi Folks Thanks for your great work. I'm trying to stimulate a response to my question by adding this comment because I'd love to be able to put (almost all) of my code that uses flask-login in a Python module that's separate from the app factory. Thanks |
Beta Was this translation helpful? Give feedback.
-
It's the same pattern as any other Flask extension. login = LoginManager()
def create_app():
app = Flask(__name__)
login.init_app(app)
return app Now you can import |
Beta Was this translation helpful? Give feedback.
If you have an
app
object, then you're not using the factory pattern. Remove that and use blueprints.