Skip to main content

Command

This class starts a lightweight web server for development that also serves static files. It extends the base runserver command to provide additional arguments for controlling static file handling, such as disabling automatic serving or forcing it when debug mode is off. The class determines whether to wrap the default handler with a static files handler based on the provided configuration and environment settings.

Attributes

AttributeTypeDescription
helpstringStarts a lightweight web server for development and also serves static files.

Methods


add_arguments()

@classmethod
def add_arguments(
parser: ArgumentParser
) - > null

Configures the command line argument parser with additional flags for controlling static file serving behavior.

Parameters

NameTypeDescription
parserArgumentParserThe argument parser instance to which the --nostatic and --insecure flags will be added.

Returns

TypeDescription
nullNothing is returned; the parser object is modified in-place.

get_handler()

@classmethod
def get_handler(
*args: tuple,
**options: dict
) - > [WSGIHandler](../../../../../core/handlers/wsgi/wsgihandler.md?sid=django_core_handlers_wsgi_wsgihandler)

Return the static files serving handler wrapping the default handler, if static files should be served. Otherwise return the default handler.

Parameters

NameTypeDescription
*argstupleVariable length argument list passed to the parent handler initialization.
**optionsdictConfiguration options containing 'use_static_handler' and 'insecure_serving' to determine if static files should be intercepted.

Returns

TypeDescription
[WSGIHandler](../../../../../core/handlers/wsgi/wsgihandler.md?sid=django_core_handlers_wsgi_wsgihandler)A WSGI handler that either includes StaticFilesHandler middleware or the standard application handler based on the provided options.