Django
runserver
web development
programming tutorial
port configuration

How to change the Django default runserver port?

Master System Design with Codemia

Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.

Introduction

Django’s development server listens on port 8000 by default, but you can change the port every time you run it by passing a host and port argument. There is no built-in project setting that permanently changes the runserver default for all invocations. If you want a stable custom port, the usual solution is a command alias, an environment-specific script, or a custom management command.

Change The Port On The Command Line

The direct way is:

bash
python manage.py runserver 8080

That starts the development server on port 8080 instead of 8000.

If you also want to control the bind address, specify host and port together:

bash
python manage.py runserver 0.0.0.0:8080

That is especially common when testing from another device on the local network or when running inside a container.

What The Default Actually Is

When you run:

bash
python manage.py runserver

Django behaves roughly like “bind to localhost on port 8000.” That is a convenience default for development only. It is not a production server configuration.

So if the real question is “how do I make the server use a different port this one time,” the answer is the command-line argument. If the real question is “how do I permanently redefine the default,” then you need to add your own wrapper around the command.

A Simple Shell Alias Or Script

Many teams solve this with a shell alias or a small script rather than changing Django internals.

bash
alias djrun='python manage.py runserver 0.0.0.0:8080'

Or a script file:

bash
#!/usr/bin/env bash
python manage.py runserver 0.0.0.0:8080

This keeps the behavior explicit and avoids surprising other developers who expect Django’s normal defaults.

Using A Custom Management Command

If you really want project-level custom behavior, you can create your own management command that wraps runserver.

python
1from django.core.management import call_command
2from django.core.management.base import BaseCommand
3
4
5class Command(BaseCommand):
6    help = "Run the development server on the team default port"
7
8    def handle(self, *args, **options):
9        call_command("runserver", "0.0.0.0:8080")

Then you could run:

bash
python manage.py devserver

That is usually better than trying to patch Django’s built-in runserver behavior globally.

Development Versus Production

It is important not to over-interpret the runserver port question. runserver is a development convenience server. In production, you normally use something like Gunicorn, uWSGI, Daphne, or another ASGI or WSGI deployment stack behind a reverse proxy.

So changing the Django dev-server port is a local workflow choice, not a production architecture decision.

When Binding To 0.0.0.0 Matters

If the server is inside Docker or you want other machines on your LAN to reach it, binding only to 127.0.0.1 is not enough.

bash
python manage.py runserver 0.0.0.0:8080

This tells Django to listen on all interfaces. Combined with container port publishing or local firewall rules, that makes the dev server reachable externally.

A Good Rule Of Thumb

Use these patterns:

  • one-off local port change: python manage.py runserver 8080,
  • external access or Docker: python manage.py runserver 0.0.0.0:8080,
  • repeatable team workflow: alias, script, or custom management command.

That covers most real-world development needs cleanly.

Common Pitfalls

  • Looking for a Django setting in settings.py that permanently changes runserver’s default port.
  • Forgetting that runserver 8080 changes only the port, not the host binding.
  • Using 127.0.0.1 when the server needs to be reachable from outside the local machine.
  • Treating runserver as a production deployment server.
  • Hiding team-specific port behavior in non-obvious local shell setup without documenting it.

Summary

  • Change the Django dev-server port by passing it to runserver, for example python manage.py runserver 8080.
  • Use 0.0.0.0:8080 when external access or containers are involved.
  • Django does not provide a normal built-in setting that permanently changes the runserver default port.
  • Use an alias, script, or custom management command if you want a repeatable project-specific port.
  • Remember that runserver is for development, not production.

Course illustration
Course illustration

All Rights Reserved.