Skip to main content

Command

Copies or symlinks static files from different locations to the settings.STATIC_ROOT.

Attributes

AttributeTypeDescription
helpstring = "Collect static files in a single location."Collect static files in a single location.
requires_system_checkslist = [Tags.staticfiles]List of system check tags that must be performed before the command can be executed.

Constructor

Signature

def Command(
*args: any,
**kwargs: any
) - > null

Parameters

NameTypeDescription
*argsanyVariable length argument list passed to the parent class constructor.
**kwargsanyArbitrary keyword arguments passed to the parent class constructor.

Methods


local()

@classmethod
def local() - > boolean

Determines if the current storage backend is local by attempting to resolve a file path. Returns False if the storage backend does not support local path access.

Returns

TypeDescription
booleanTrue if the storage is local and supports path resolution, False otherwise

add_arguments()

@classmethod
def add_arguments(
parser: ArgumentParser
)

Configures the command-line argument parser with options for interactivity, post-processing, file ignoring, dry runs, clearing, and symlinking.

Parameters

NameTypeDescription
parserArgumentParserThe argument parser instance to which collectstatic-specific arguments will be added

set_options()

@classmethod
def set_options(
**options: dict
)

Set instance variables based on an options dict

Parameters

NameTypeDescription
**optionsdictA dictionary of configuration options typically parsed from the command line

collect()

@classmethod
def collect() - > dict

Perform the bulk of the work of collectstatic. Split off from handle() to facilitate testing.

Returns

TypeDescription
dictA dictionary containing lists of paths for modified, unmodified, post-processed, skipped, and deleted files

handle()

@classmethod
def handle(
**options: dict
) - > string

Executes the command logic, including user confirmation prompts and reporting the final summary of collected files. This is the main entry point for the management command.

Parameters

NameTypeDescription
**optionsdictCommand-line options that control the behavior of the collection process

Returns

TypeDescription
stringA formatted summary string detailing the number of files copied, symlinked, or skipped

log()

@classmethod
def log(
msg: string,
level: integer
)

Small log helper

Parameters

NameTypeDescription
msgstringThe message string to be written to standard output
levelintegerThe verbosity threshold required to display this message

is_local_storage()

@classmethod
def is_local_storage() - > boolean

Checks if the configured storage backend is an instance of FileSystemStorage. This is used to determine if local filesystem operations are applicable.

Returns

TypeDescription
booleanTrue if the storage backend is local filesystem storage, False otherwise

clear_dir()

@classmethod
def clear_dir(
path: string
)

Delete the given relative path using the destination storage backend.

Parameters

NameTypeDescription
pathstringThe relative directory path within the storage backend to be cleared

delete_file()

@classmethod
def delete_file(
path: string,
prefixed_path: string,
source_storage: [Storage](../../../../../core/files/storage/base/storage.md?sid=django_core_files_storage_base_storage)
) - > boolean

Check if the target file should be deleted if it already exists.

Parameters

NameTypeDescription
pathstringThe relative path of the file in the source storage
prefixed_pathstringThe destination path including any configured prefixes
source_storage[Storage](../../../../../core/files/storage/base/storage.md?sid=django_core_files_storage_base_storage)The storage instance where the source file is located

Returns

TypeDescription
booleanTrue if the file was deleted or can be overwritten, False if the file is unmodified and should be skipped

@classmethod
def link_file(
path: string,
prefixed_path: string,
source_storage: [Storage](../../../../../core/files/storage/base/storage.md?sid=django_core_files_storage_base_storage)
)

Attempt to link path

Parameters

NameTypeDescription
pathstringThe relative path of the source file
prefixed_pathstringThe destination path where the symbolic link will be created
source_storage[Storage](../../../../../core/files/storage/base/storage.md?sid=django_core_files_storage_base_storage)The storage instance containing the source file

copy_file()

@classmethod
def copy_file(
path: string,
prefixed_path: string,
source_storage: [Storage](../../../../../core/files/storage/base/storage.md?sid=django_core_files_storage_base_storage)
)

Attempt to copy path with storage

Parameters

NameTypeDescription
pathstringThe relative path of the source file
prefixed_pathstringThe destination path where the file will be saved
source_storage[Storage](../../../../../core/files/storage/base/storage.md?sid=django_core_files_storage_base_storage)The storage instance from which the file will be read