Skip to Content
Flask Framework Cookbook - Second Edition
book

Flask Framework Cookbook - Second Edition

by Shalabh Aggarwal
July 2019
Beginner to intermediate
302 pages
9h 38m
English
Packt Publishing
Content preview from Flask Framework Cookbook - Second Edition

How to do it...

Adding a simple admin interface to any Flask application using the Flask-Admin extension is just a matter of a couple of statements:

  1. Simply add the following lines to the application's configuration in my_app/__init__.py:
from flask_admin import Admin 
 
app = Flask(__name__) 
 
# Add any other application configuration 
 
admin = Admin(app) 
  1. You can also add your own views to this; this is as simple as adding a new class as a new view that inherits from the BaseView class, as shown in the following code block. This code block goes in auth/views.py:
from flask_admin import BaseView, expose 
 
class HelloView(BaseView): 
    @expose('/') 
    def index(self): 
        return self.render('some-template.html') 

After this, add this view to the admin object ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Writing a Web Application with Flask

Writing a Web Application with Flask

Doug Farrell
Mastering Flask

Mastering Flask

Jack Stouffer

Publisher Resources

ISBN: 9781789951295Supplemental Content