I am using flask-admin, and I want to add a dashboard to the home page. I found I can add a new page using:
admin = Admin(name='Dashboard', base_template='admin/my_master.html', template_mode='bootstrap3')
then:
admin.init_app(app)
and finally I added my_master.html, and added content. However, it is all static, how can I add custom data to that view?
In a world of micro-services and APIs, Flask-Admin solves the boring problem of building an admin interface on top of an existing data model. With little effort, it lets you manage your web service's data through a user-friendly interface.
I found the answer in the documentation: http://flask-admin.readthedocs.org/en/latest/api/mod_base/
It can be overridden by passing your own view class to the Admin constructor:
class MyHomeView(AdminIndexView):
@expose('/')
def index(self):
arg1 = 'Hello'
return self.render('admin/myhome.html', arg1=arg1)
admin = Admin(index_view=MyHomeView())
Also, you can change the root url from /admin to / with the following:
admin = Admin(
app,
index_view=AdminIndexView(
name='Home',
template='admin/myhome.html',
url='/'
)
)
Default values for the index page are:
According to flask-admin documentation use this:
from flask_admin import BaseView, expose
class AnalyticsView(BaseView):
@expose('/')
def index(self):
return self.render('analytics_index.html', args=args)
admin.add_view(AnalyticsView(name='Analytics', endpoint='analytics'))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With