from flask_admin import Admin, BaseView, expose from flask_admin.menu import MenuLink # Define view class MyView(BaseView): @expose('/') def index(self): return self.render('mytemplate.html') # Create Flask-Admin instance admin = Admin() # Add view to Flask-Admin instance admin.add_view(MyView(name='My View')) # Add external link to Flask-Admin menu admin.add_link(MenuLink(name='Google', url='https://www.google.com'))
from flask import Flask, url_for from flask_admin import Admin, BaseView, expose from flask_admin.menu import MenuLink # Define Flask app app = Flask(__name__) # Define view class MyView(BaseView): @expose('/') def index(self): return self.render('mytemplate.html') # Create Flask-Admin instance admin = Admin(app) # Add view to Flask-Admin instance admin.add_view(MyView(name='My View')) # Add internal Flask route to Flask-Admin menu admin.add_link(MenuLink(name='Home', url=url_for('index')))In this example, we define a custom view named "MyView" and add it to the Flask-Admin instance. We also add an internal Flask route to the Flask-Admin menu named "Home" that directs users to the Flask app homepage using url_for().