I'm following this instruction http://ift.tt/2kNjqIe
However, i don't understand how do i share app object to other package like Flask-Admin?
For now, i'm passing app
object around like this (app/init.py):
from .admin import register_admin
def create_app():
app = Flask(__name__)
...
register_admin(app)
...
return app
I have admin folder, i want to put all code about admin execution here like routing, config, admin info ... In the app/admin/__init__.py
file:
from flask_admin import Admin
def register_admin(app):
Admin(app, name='admin', template_mode='bootstrap3')
But by doing this way there are few things make me confused:
- I have to pass
app
object around, i don't thing this is good practice -
Even if i don't access to
http://localhost:5000/admin
path, theregister_admin
method still being called at the initialization - I want register admin only when user access to admin panel -
Every piece of code i put inside
create_app
will be execute twice even after puttingif __name__ == '__main__'
inrun.py
file ?!!
Aucun commentaire:
Enregistrer un commentaire