Managing static assets via the Admin

Flask-Admin provides a convenient interface for managing static assets (or other files on disk) as an extension to the admin dashboard. Let's add a FileAdmin to our site that will allow us to upload or modify files in our application's static directory.

Open admin.py and import the following module at the top of the file:

from flask.ext.admin.contrib.fileadmin import FileAdmin

Then, below the various ModelView implementations, add the following highlighted lines of code:

class BlogFileAdmin(FileAdmin):
    pass

admin = Admin(app, 'Blog Admin')
admin.add_view(EntryModelView(Entry, db.session))
admin.add_view(SlugModelView(Tag, db.session))
admin.add_view(UserModelView(User, db.session))
admin.add_view(
 BlogFileAdmin(app.config['STATIC_DIR'], ...

Get Learning Flask Framework now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.