Skip to main content

Command

This class implements a lightweight web server designed for development environments. It provides features such as automatic code reloading, multi-threading support, and IPv6 compatibility while performing essential system and migration checks before startup. The class interfaces with a WSGI handler to serve applications and includes configurable options for address and port binding.

Attributes

AttributeTypeDescription
helpstring = "Starts a lightweight web server for development."Starts a lightweight web server for development.
stealth_optionstuple = ("shutdown_message",)Tuple of internal command-line options that are not displayed in the help message, such as the shutdown message.
suppressed_base_argumentsset = {"--verbosity", "--traceback"}Set of default command-line arguments from the base command class that should be hidden from this command's interface.
default_addrstring = "127.0.0.1"The default IPv4 address the development server binds to when no address is provided.
default_addr_ipv6string = "::1"The default IPv6 address the development server binds to when the IPv6 flag is enabled and no address is provided.
default_portstring = "8000"The default port number the development server listens on if none is specified by the user.
protocolstring = "http"The network protocol used for the server, primarily used for generating the display URL in the console.
server_clsclass = WSGIServerThe WSGI server class used to instantiate and run the development web server.

Methods


add_arguments()

@classmethod
def add_arguments(
parser: [CommandParser](../../base/commandparser.md?sid=django_core_management_base_commandparser)
) - > null

Configures the command line argument parser with options for the server address, port, IPv6 support, threading, and auto-reloading.

Parameters

NameTypeDescription
parser[CommandParser](../../base/commandparser.md?sid=django_core_management_base_commandparser)The argument parser instance to which runserver-specific arguments will be added.

Returns

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

execute()

@classmethod
def execute(
*args: tuple,
**options: dict
) - > null

Wraps the base command execution to set environment variables for color output before proceeding with standard command logic.

Parameters

NameTypeDescription
*argstupleVariable length argument list passed to the base execution method.
**optionsdictCommand line options, including 'no_color' which affects the DJANGO_COLORS environment variable.

Returns

TypeDescription
nullNothing is returned; it triggers the command execution flow.

get_handler()

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

Return the default WSGI handler for the runner.

Parameters

NameTypeDescription
*argstuplePositional arguments passed during handler retrieval.
**optionsdictConfiguration options used to determine how the handler should be initialized.

Returns

TypeDescription
[WSGIHandler](../../../handlers/wsgi/wsgihandler.md?sid=django_core_handlers_wsgi_wsgihandler)The internal WSGI application used to process incoming web requests.

get_check_kwargs()

@classmethod
def get_check_kwargs(
options: dict
) - > dict

Validation is called explicitly each time the server reloads.

Parameters

NameTypeDescription
optionsdictThe command options used to configure the system check parameters.

Returns

TypeDescription
dictA dictionary containing configuration for system checks, specifically initializing an empty set of tags.

handle()

@classmethod
def handle(
*args: tuple,
**options: dict
) - > null

Validates settings and parses the provided address and port before initiating the server run loop.

Parameters

NameTypeDescription
*argstuplePositional arguments provided to the command.
**optionsdictParsed command line options including 'addrport' and 'use_ipv6'.

Returns

TypeDescription
nullNothing is returned; this method transitions control to the run method.

run()

@classmethod
def run(
**options: dict
) - > null

Run the server, using the autoreloader if needed.

Parameters

NameTypeDescription
**optionsdictConfiguration options that determine whether to use the auto-reloader.

Returns

TypeDescription
nullNothing is returned; this method enters a blocking loop to serve requests.

inner_run()

@classmethod
def inner_run(
*args: tuple,
**options: dict
) - > null

Executes the core server logic, including system checks, migration verification, and starting the WSGI server instance.

Parameters

NameTypeDescription
*argstuplePositional arguments passed from the reloader or run method.
**optionsdictRuntime options including threading preferences and check-skipping flags.

Returns

TypeDescription
nullNothing is returned; the method runs the server until interrupted or an error occurs.

on_bind()

@classmethod
def on_bind(
server_port: string
) - > null

Logs server startup information to the console, including the Django version, active settings, and the local URL once the port is bound.

Parameters

NameTypeDescription
server_portstringThe actual port number the server has successfully bound to.

Returns

TypeDescription
nullNothing is returned; this method performs I/O by printing to stdout.