Coder Social home page Coder Social logo

Comments (2)

mrjoes avatar mrjoes commented on July 21, 2024

I see. You create new application object, but what forbids you to create
new Admin class instance as well?

Idea was to prevent reinitialization of the Admin class after it was
associated with Flask app.

I you see a problem with this approach, can you provide a use case?

28.05.2012 11:14 пользователь "ivirabyan" <
[email protected]>
написал:

I'm using application factory, and as a result, using admin.init_app()
method inside of create_app function. Unit tests create a new app app on
each run, so that init_app gets called multiple times. The problem is that
it raises on second run:
Exception: Flask-Admin is already associated with an application

Application fabrics are widely used for unittesting, and another
extensions, like flask-sqlalchemy allow reinitialization with another app.
For now I hack this like this:
admin.app = None
admin.init_app(app)


Reply to this email directly or view it on GitHub:
mrjoes/flask-admin#22

from flask-admin.

ivirabyan avatar ivirabyan commented on July 21, 2024

admin class instance created at module level, so that it is available to other modules. Just like db instance of sqlalchemy. See an example:

app.py:

db = SQLAlchemy()
admin = Admin()

def create_app(config=None):
    app = Flask(__name__)
    if config is not None:
        app.config.from_object(config)

    db.init_app(app)
    admin.init_app(app)
    return app

views.py:

from app import db
...

admin.py:

from app import admin
...
admin.add_view(ModelView(Banner, db.session))

Of course I can move admin.add_view() to create_app, but there are too much calls, and I want to keep my create_app() clean. Admin stuff should lie in admin.py

from flask-admin.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.