The Development Server

Run your project locally with manage.py runserver.

Syntaxpython manage.py runserver [addr:port]

Django ships with a lightweight development web server. Start it with runserver and visit http://127.0.0.1:8000. It auto-reloads whenever you edit a file.

The dev server is for development only — never use it in production (see the Deployment chapter).

Example

Example · bash
# Start the server (default port 8000)
python manage.py runserver

# Use a different port
python manage.py runserver 8080

# Listen on all interfaces
python manage.py runserver 0.0.0.0:8000

When to use it

  • A developer runs the Django dev server on port 8080 to avoid a conflict with another service on 8000.
  • A team member starts the server bound to 0.0.0.0 so colleagues on the same LAN can test the app.
  • A developer uses --noreload to prevent the dev server from restarting during performance profiling sessions.

More examples

Start default dev server

Starts Django's built-in development server on localhost port 8000.

Example · bash
python manage.py runserver
# Listening on http://127.0.0.1:8000/

Custom host and port

Binds the server to all interfaces on port 8080 so it can be reached from other devices.

Example · bash
python manage.py runserver 0.0.0.0:8080

Select settings module at startup

Uses an environment variable to select a custom settings module before starting the server.

Example · bash
DJANGO_SETTINGS_MODULE=mysite.settings.local \
  python manage.py runserver

Discussion

  • Be the first to comment on this lesson.