flask_admin.contrib.fileadmin

class FileAdmin(base_path: str | bytes, *args: Any, **kwargs: Any)[source]

Simple file-management interface.

Parameters:
  • base_path – Path to the directory which will be managed

  • base_url – Optional base URL for the directory. Will be used to generate static links to the files. If not defined, a route will be created to serve uploaded files.

Sample usage:

import os.path as op

from flask_admin import Admin
from flask_admin.contrib.fileadmin import FileAdmin

admin = Admin()

path = op.join(op.dirname(__file__), 'static')
admin.add_view(FileAdmin(path, '/static/', name='Static Files'))

Constructor.

Parameters:
  • base_url – Base URL for the files

  • name – Name of this view. If not provided, will default to the class name.

  • category – View category

  • endpoint – Endpoint name for the view

  • url – URL for view

  • verify_path – Verify if path exists. If set to True and path does not exist will raise an exception.

  • storage – The storage backend that the BaseFileAdmin will use to operate on the files.

can_upload = True

Is file upload allowed.

can_delete = True

Is file deletion allowed.

can_delete_dirs = True

Is recursive directory deletion is allowed.

can_mkdir = True

Is directory creation allowed.

can_rename = True

Is file and directory renaming allowed.

allowed_extensions = None

List of allowed extensions for uploads, in lower case.

Example:

class MyAdmin(FileAdmin):
    allowed_extensions = ('swf', 'jpg', 'gif', 'png')
editable_extensions: t.Collection[str] = ()

List of editable extensions, in lower case.

Example:

class MyAdmin(FileAdmin):
    editable_extensions = ('md', 'html', 'txt')
list_template = 'admin/file/list.html'

File list template

upload_template = 'admin/file/form.html'

File upload template

mkdir_template = 'admin/file/form.html'

Directory creation (mkdir) template

rename_template = 'admin/file/form.html'

Rename template

edit_template = 'admin/file/form.html'

Edit template

delete() Response | Response

Delete view method

download(path: str | None = None) Response | Response

Download view method.

Parameters:

path – File path.

edit() Response | Response | str

Edit view method

index_view(path: str | None = None) Response | Response | str

Index view method

Parameters:

path – Optional directory path. If not provided, will use the base directory

mkdir(path: str | None = None) Response | Response | str

Directory creation view method

Parameters:

path – Optional directory path. If not provided, will use the base directory

rename() Response | Response | str

Rename view method

upload(path: str | None = None) Response | Response | str

Upload view method

Parameters:

path – Optional directory path. If not provided, will use the base directory