localhost:8000

http://localhost:8000

Port 8000 is the default development port for Django and Python's built-in HTTP server. It's also commonly used by Flask, FastAPI, and other Python web frameworks for local application development and testing.

→ Open localhost:8000

What Uses Port 8000?

Port 8000 is the standard development port for many Python applications:

  • Django - Default development server port (runserver command)
  • Python http.server - Built-in simple HTTP server module
  • Flask - Alternative port for Flask web applications
  • FastAPI - Modern Python web framework default port
  • Tornado - Python web framework and networking library
  • CherryPy - Object-oriented Python web framework
  • Pyramid - Python web application framework
  • Bottle - Lightweight Python web micro-framework
  • aiohttp - Async HTTP client/server framework
  • Sanic - Async Python web server framework

How to Start Servers on Port 8000

Django Development Server

# Start Django development server (default port 8000) python manage.py runserver # Explicitly specify port 8000 python manage.py runserver 8000 # Listen on all network interfaces python manage.py runserver 0.0.0.0:8000 # Use different port if 8000 is busy python manage.py runserver 8001 # Access at: http://localhost:8000

Python Built-in HTTP Server

# Python 3.x - Simple HTTP server on port 8000 python -m http.server 8000 # Python 3 - Specify directory to serve python -m http.server 8000 --directory /path/to/folder # Python 3 - Bind to specific host python -m http.server 8000 --bind 127.0.0.1 # Python 2.x (deprecated) - SimpleHTTPServer python -m SimpleHTTPServer 8000 # Access at: http://localhost:8000

Flask Application

# Flask app.py from flask import Flask app = Flask(__name__) @app.route('/') def hello(): return 'Hello from Flask on port 8000!' if __name__ == '__main__': app.run(host='localhost', port=8000, debug=True) # Run Flask app python app.py # Or use flask run command flask run --host=localhost --port=8000 # Access at: http://localhost:8000

FastAPI Application

# main.py from fastapi import FastAPI import uvicorn app = FastAPI() @app.get("/") def read_root(): return {"message": "Hello from FastAPI on port 8000"} if __name__ == "__main__": uvicorn.run(app, host="localhost", port=8000) # Run FastAPI app python main.py # Or use uvicorn directly uvicorn main:app --host localhost --port 8000 --reload # Access at: http://localhost:8000 # API docs at: http://localhost:8000/docs

Tornado Web Server

# server.py import tornado.ioloop import tornado.web class MainHandler(tornado.web.RequestHandler): def get(self): self.write("Hello from Tornado on port 8000!") app = tornado.web.Application([ (r"/", MainHandler), ]) if __name__ == "__main__": app.listen(8000) print("Server running at http://localhost:8000") tornado.ioloop.IOLoop.current().start() # Run: python server.py

Django Development Server Complete Guide

Basic Django Project Setup

# Install Django pip install django # Create new Django project django-admin startproject myproject # Navigate to project directory cd myproject # Create database tables python manage.py migrate # Create superuser for admin python manage.py createsuperuser # Start development server python manage.py runserver # Django server starts at http://localhost:8000 # Admin panel available at http://localhost:8000/admin

Django Server Options

# Default: localhost:8000 python manage.py runserver # Custom port python manage.py runserver 8080 # Custom host and port python manage.py runserver 192.168.1.100:8000 # Listen on all interfaces python manage.py runserver 0.0.0.0:8000 # Disable auto-reload python manage.py runserver --noreload # Use IPv6 python manage.py runserver -6 python manage.py runserver [::]:8000 # Multithreading support python manage.py runserver --nothreading

Django Settings for Development

# settings.py - Development configuration # Allow all hosts for local development ALLOWED_HOSTS = ['localhost', '127.0.0.1', '[::1]'] # Enable debug mode DEBUG = True # Database configuration (SQLite for development) DATABASES = { 'default': { 'ENGINE': 'django.db.backends.sqlite3', 'NAME': BASE_DIR / 'db.sqlite3', } } # Static files configuration STATIC_URL = '/static/' STATIC_ROOT = BASE_DIR / 'staticfiles' # Media files configuration MEDIA_URL = '/media/' MEDIA_ROOT = BASE_DIR / 'media'

How to Fix "localhost:8000 Not Working"

Error: "That port is already in use"

Another process is using port 8000.

  • Find the process using port 8000
  • Kill the existing process
  • Use an alternative port like 8001 or 8080
  • Check for multiple Django instances running
# Windows - Find process on port 8000 netstat -ano | findstr :8000 tasklist | findstr [PID] taskkill /F /PID [process_id] # Linux/Mac - Find and kill process lsof -i :8000 sudo lsof -ti:8000 | xargs kill -9 # Alternative: Use different port python manage.py runserver 8001

Error: "Connection refused" at localhost:8000

Server is not running or not accessible.

  • Verify Django/Python server is actually running
  • Check for error messages in terminal
  • Ensure firewall isn't blocking port 8000
  • Try 127.0.0.1:8000 instead of localhost:8000
  • Check if server crashed due to code error

Error: "DisallowedHost at /"

Django ALLOWED_HOSTS configuration issue.

  • Add hostname to ALLOWED_HOSTS in settings.py
  • For development, use: ALLOWED_HOSTS = ['*']
  • Or specific hosts: ALLOWED_HOSTS = ['localhost', '127.0.0.1']
  • Restart Django server after changing settings

Error: "ModuleNotFoundError" or Import Errors

Python dependencies not installed or virtual environment not activated.

  • Activate virtual environment: source venv/bin/activate
  • Install requirements: pip install -r requirements.txt
  • Verify Python path is correct
  • Check if running correct Python version
Check Port 8000 Status:
# Windows - Check if port 8000 is listening netstat -an | findstr :8000 # Linux - Check port 8000 sudo netstat -tulpn | grep :8000 sudo ss -tulpn | grep :8000 lsof -i :8000 # Mac - Check port 8000 lsof -i :8000 netstat -an | grep 8000 # Test connection to port 8000 curl http://localhost:8000 telnet localhost 8000 # Use nc (netcat) to test nc -zv localhost 8000

Django Virtual Environment Setup

Always use virtual environments for Python projects:

Create and Activate Virtual Environment

# Create virtual environment python -m venv venv # Windows - Activate virtual environment venv\Scripts\activate # Linux/Mac - Activate virtual environment source venv/bin/activate # Install Django in virtual environment pip install django # Install additional packages pip install djangorestframework pip install pillow # For image handling pip install psycopg2 # For PostgreSQL # Save dependencies pip freeze > requirements.txt # Deactivate virtual environment deactivate

Install from requirements.txt

# Install all project dependencies pip install -r requirements.txt # Upgrade pip first (recommended) python -m pip install --upgrade pip pip install -r requirements.txt

Python Web Framework Comparison

Framework Default Port Type Best For
Django 8000 Full-stack Large applications, admin panel
Flask 5000 Micro-framework Small to medium applications
FastAPI 8000 Modern, async APIs, high performance
Tornado 8888 Async Real-time, WebSocket
Bottle 8080 Micro-framework Simple, single-file apps
Pyramid 6543 Full-stack Flexible, scalable apps

Django Project Structure

myproject/ ├── manage.py # Django management script ├── myproject/ # Project configuration directory │ ├── __init__.py │ ├── settings.py # Project settings │ ├── urls.py # URL routing │ ├── wsgi.py # WSGI configuration │ └── asgi.py # ASGI configuration ├── myapp/ # Django application │ ├── migrations/ # Database migrations │ ├── __init__.py │ ├── admin.py # Admin configuration │ ├── apps.py # App configuration │ ├── models.py # Database models │ ├── tests.py # Unit tests │ └── views.py # View functions ├── templates/ # HTML templates ├── static/ # Static files (CSS, JS, images) ├── media/ # User uploaded files ├── venv/ # Virtual environment └── requirements.txt # Python dependencies

Django Debug Tools

Enable Django Debug Toolbar

# Install debug toolbar pip install django-debug-toolbar # Add to settings.py INSTALLED_APPS INSTALLED_APPS = [ # ... 'debug_toolbar', ] # Add to MIDDLEWARE MIDDLEWARE = [ # ... 'debug_toolbar.middleware.DebugToolbarMiddleware', ] # Add to settings.py INTERNAL_IPS = [ '127.0.0.1', ] # Add to urls.py import debug_toolbar urlpatterns = [ path('__debug__/', include(debug_toolbar.urls)), # ... your patterns ]

Django Shell for Testing

# Open Django shell python manage.py shell # Test database queries from myapp.models import MyModel objects = MyModel.objects.all() print(objects) # Exit shell exit()

Common Django Development Tasks

Database Operations

# Create new migrations after model changes python manage.py makemigrations # Apply migrations to database python manage.py migrate # Show migrations status python manage.py showmigrations # Create SQL for migration python manage.py sqlmigrate myapp 0001 # Reset database (SQLite) # Delete db.sqlite3 file and run: python manage.py migrate

Static Files Management

# Collect static files python manage.py collectstatic # Clear cached static files python manage.py collectstatic --clear --noinput

User Management

# Create superuser python manage.py createsuperuser # Change user password python manage.py changepassword username

Django Production vs Development

Setting Development Production
DEBUG True False
ALLOWED_HOSTS ['localhost', '127.0.0.1'] ['yourdomain.com']
Server runserver (port 8000) Gunicorn/uWSGI + Nginx
Database SQLite PostgreSQL/MySQL
Static Files Served by Django Served by Nginx/CDN
SECRET_KEY In settings.py Environment variable
Important: Django's development server (runserver) is NOT suitable for production use. It's single-threaded, doesn't handle concurrent requests well, and lacks security features. Use Gunicorn, uWSGI, or similar WSGI servers for production deployments.

Frequently Asked Questions

How do I access Django server from another computer?

Run python manage.py runserver 0.0.0.0:8000 and access using your computer's IP address (e.g., http://192.168.1.100:8000). Ensure firewall allows connections.

Can I change Django's default port?

Yes, use python manage.py runserver 8080 or any available port. You can also set it in your IDE's run configuration.

Why does Django server auto-reload?

Django detects code changes and automatically restarts the server for convenience. Disable with --noreload flag if needed.

Is port 8000 secure?

Port 8000 uses HTTP (unencrypted). For development it's fine, but production should use HTTPS on port 443 with proper SSL certificates.

Related Resources