Comments (7)
The topic list is now closed, maybe if I do another round of updates at some point. But I honestly don't see much educational value in showing how to use Flask-Admin, while the extension can be useful for some types of applications, it does not really teach any new concepts. My suggestion is that you fork the project and work on adding it yourself as an exercise.
from microblog.
Thanks. Would you accept pull requests on this repository (if it meets the coding style)?
from microblog.
Also, Flask_Admin is a good example of circular import in multi-file flask projects (models needs db, admin needs models, and create_app register Admin_views)
from microblog.
I can't accept it on this repository because it will be out of sync with the tutorial, but I can leave the PR here for others that are interested in seeing how you integrated it.
from microblog.
Did you ever resolve this ? Can you show how you managed to get around circular import ?
from microblog.
Yes, I did. I've flask_admin working well with this microblog (or flasky) as the base template for the structure.
in app/__init__.py (where you have the create_app function), don't import your admin package on the top, rather, import it inside the create_app function. Here is an example:
app/__init__.py:
from flask import Flask
from config import config
from flask_mongoengine import MongoEngine
from flask_mail import Mail
from flask_bootstrap import Bootstrap
from flask_admin import Admin
from flask_login import LoginManager
from flask_debugtoolbar import DebugToolbarExtension
from flask_moment import Moment
mail = Mail()
db = MongoEngine()
bootstrap = Bootstrap()
app_admin = Admin(name='My admin name', template_mode='bootstrap3',
base_template='admin/custom_base.html')
login_manager = LoginManager()
login_manager.login_view = 'auth.login'
moment = Moment()
toolbar = DebugToolbarExtension()
def create_app(config_name):
app = Flask(__name__)
app.config.from_object(config[config_name])
# init
mail.init_app(app)
db.init_app(app)
bootstrap.init_app(app)
login_manager.init_app(app)
app_admin.init_app(app)
moment.init_app(app)
toolbar.init_app(app)
from .auth import auth as auth_blueprint
app.register_blueprint(auth_blueprint, url_prefix='/auth')
from .main import main as main_blueprint
app.register_blueprint(main_blueprint)
# To avoid circular import
from app.admin import add_admin_views
add_admin_views()
return app
Then in the app/admin.py:
def add_admin_views():
"""Register views to admin"""
from .. import app_admin
app_admin.add_view(SoftwareView(Software, name='Software List'))
app_admin.add_view(UserView(User, name='Users'))
from microblog.
@doaa-altarawy, seems a good way to handle the problem, I am so convinced before I try it out. Thanks.
from microblog.
Related Issues (20)
- Did you check documentation? HOT 2
- AttributeError: 'Babel' object has no attribute 'localeselector' HOT 2
- hi HOT 2
- 2023 update
- Popover does not work in chapter 20 due to bootstrapcdn source issue? HOT 5
- Member redis is unknown HOT 2
- Chapter 14 Translations fail unless the destination language is explicitly specified
- Chapter 22 Export task stuck at 0% HOT 5
- elastic_transport.ConnectionError when post is submitted? HOT 6
- Language inconsistency during poedit translation process? HOT 7
- Using JinJa2 filter function truncate to implement 'Read more'? HOT 21
- Bug in lesson 5 due to werkzeug.urls - url parsing removed HOT 4
- Lesson 6, FLASK_ENV is removed from Flask 2.3.0 HOT 2
- Unable to load celery application. 'str' object has no attribute 'level' when Integrating Celery with Flask? HOT 17
- Unable to import 'url_parse' from 'werkzeug.urls' in flask shell execution HOT 15
- login error was reported during deployment? HOT 7
- Github links in chapters start with wrong tag (one-off) HOT 2
- Dead link to flask-babel docs HOT 1
- flask_moment error when trying to format HOT 4
- Multidict Package Problematic in python:slim HOT 1
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 microblog.