Comments (2)
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 applicationApplication 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.
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)
- Unable to Render Flask-Admin Edit Form Fields for Variables Stored as JSON HOT 1
- Seeking help from additional volunteers? HOT 7
- Creating custom views for BaseView grouped in a category and passing an id HOT 1
- Can't use multiple `Admin` instances with different Bootstrap themes (`FLASK_ADMIN_SWATCH`) HOT 14
- Flask Admin Reboot: A community version to submit changes HOT 6
- [not issue] Implement flask-admin in Go HOT 2
- QuerySelectField ignores changes to data / default in ModelView.create_form HOT 2
- `can_set_page_size` does not prevent custom page sizes
- Multiple requests caused by 'create_modal' HOT 4
- Add Pallets-eco notice
- Mirror Pallets-eco setup for projects HOT 4
- Comparasing between objects causes crash if _eq_ of db model class is "occupied" HOT 1
- Disable typing in tests
- Add typing support to project HOT 1
- Deprecate flask-babelex; use flask-babel again
- Template Mode w/ Tabler
- Remove Flask-BabelEx support? HOT 2
- Update Python compatibility
- Plan for next release - v2.0 HOT 6
- Use `extras` to define packaging options and their dependencies
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from flask-admin.