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

There's more...

After implementing the preceding code, there is still an admin view that won't be completely user-protected and will be publicly available. This will be the admin home page. To make this available only to the admins, we have to inherit from AdminIndexView and implement is_accessible():

from flask_admin import AdminIndexView 
 
class MyAdminIndexView(AdminIndexView): 
    def is_accessible(self): 
        return current_user.is_authenticated and current_user.is_admin() 

Then, just pass this view to the admin object in the application's configuration as index_view, and we are done:

admin = Admin(app, index_view=views.MyAdminIndexView())

This approach makes all our admin views accessible only to the admin users. We can also implement any permission ...

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