Book Image

Learning Flask Framework

Book Image

Learning Flask Framework

Overview of this book

Table of Contents (17 chapters)
Learning Flask Framework
Credits
About the Authors
About the Reviewers
www.PacktPub.com
Preface
Index

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'], '/static/', name='Static Files'))

Pulling up the admin in your browser, you should see a new tab labeled Static Files. Clicking this link will take you to a familiar file-browser, as seen in the following screenshot...