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
| Attribute | Type | Description |
|---|
| help | string = "Starts a lightweight web server for development." | Starts a lightweight web server for development. |
| stealth_options | tuple = ("shutdown_message",) | Tuple of internal command-line options that are not displayed in the help message, such as the shutdown message. |
| suppressed_base_arguments | set = {"--verbosity", "--traceback"} | Set of default command-line arguments from the base command class that should be hidden from this command's interface. |
| default_addr | string = "127.0.0.1" | The default IPv4 address the development server binds to when no address is provided. |
| default_addr_ipv6 | string = "::1" | The default IPv6 address the development server binds to when the IPv6 flag is enabled and no address is provided. |
| default_port | string = "8000" | The default port number the development server listens on if none is specified by the user. |
| protocol | string = "http" | The network protocol used for the server, primarily used for generating the display URL in the console. |
| server_cls | class = WSGIServer | The 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
| Name | Type | Description |
|---|
| parser | [CommandParser](../../base/commandparser.md?sid=django_core_management_base_commandparser) | The argument parser instance to which runserver-specific arguments will be added. |
Returns
| Type | Description |
|---|
null | Nothing 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
| Name | Type | Description |
|---|
| *args | tuple | Variable length argument list passed to the base execution method. |
| **options | dict | Command line options, including 'no_color' which affects the DJANGO_COLORS environment variable. |
Returns
| Type | Description |
|---|
null | Nothing 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
| Name | Type | Description |
|---|
| *args | tuple | Positional arguments passed during handler retrieval. |
| **options | dict | Configuration options used to determine how the handler should be initialized. |
Returns
| Type | Description |
|---|
[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
| Name | Type | Description |
|---|
| options | dict | The command options used to configure the system check parameters. |
Returns
| Type | Description |
|---|
dict | A 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
| Name | Type | Description |
|---|
| *args | tuple | Positional arguments provided to the command. |
| **options | dict | Parsed command line options including 'addrport' and 'use_ipv6'. |
Returns
| Type | Description |
|---|
null | Nothing 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
| Name | Type | Description |
|---|
| **options | dict | Configuration options that determine whether to use the auto-reloader. |
Returns
| Type | Description |
|---|
null | Nothing 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
| Name | Type | Description |
|---|
| *args | tuple | Positional arguments passed from the reloader or run method. |
| **options | dict | Runtime options including threading preferences and check-skipping flags. |
Returns
| Type | Description |
|---|
null | Nothing 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
| Name | Type | Description |
|---|
| server_port | string | The actual port number the server has successfully bound to. |
Returns
| Type | Description |
|---|
null | Nothing is returned; this method performs I/O by printing to stdout. |