Copies or symlinks static files from different locations to the settings.STATIC_ROOT.
Attributes
| Attribute | Type | Description |
|---|
| help | string = "Collect static files in a single location." | Collect static files in a single location. |
| requires_system_checks | list = [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
| Name | Type | Description |
|---|
| *args | any | Variable length argument list passed to the parent class constructor. |
| **kwargs | any | Arbitrary 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
| Type | Description |
|---|
boolean | True 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
| Name | Type | Description |
|---|
| parser | ArgumentParser | The 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
| Name | Type | Description |
|---|
| **options | dict | A 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
| Type | Description |
|---|
dict | A 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
| Name | Type | Description |
|---|
| **options | dict | Command-line options that control the behavior of the collection process |
Returns
| Type | Description |
|---|
string | A formatted summary string detailing the number of files copied, symlinked, or skipped |
log()
@classmethod
def log(
msg: string,
level: integer
)
Small log helper
Parameters
| Name | Type | Description |
|---|
| msg | string | The message string to be written to standard output |
| level | integer | The 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
| Type | Description |
|---|
boolean | True 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
| Name | Type | Description |
|---|
| path | string | The 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
| Name | Type | Description |
|---|
| path | string | The relative path of the file in the source storage |
| prefixed_path | string | The 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
| Type | Description |
|---|
boolean | True if the file was deleted or can be overwritten, False if the file is unmodified and should be skipped |
link_file()
@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
| Name | Type | Description |
|---|
| path | string | The relative path of the source file |
| prefixed_path | string | The 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
| Name | Type | Description |
|---|
| path | string | The relative path of the source file |
| prefixed_path | string | The 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 |