← Back to Chapters

Running the Development Server

? Running the Development Server

? Quick Overview

Django provides a built-in lightweight web server that helps you preview your application during development. It automatically reloads when you make changes, making it ideal for rapid testing.

? Key Concepts

  • The development server is started using the manage.py utility.
  • It runs locally and listens on port 8000 by default.
  • It should never be used in a production environment.

? Step 1: Navigate to the Project Directory

Before running the server, make sure you're in the directory that contains your manage.py file.

? View Code Example
// Navigate to the Django project directory
cd myproject

Replace myproject with the actual name of your project folder.

▶️ Step 2: Run the Development Server

Once inside the project directory, execute the following command to start the server:

? View Code Example
// Start the Django development server
python manage.py runserver

By default, the server runs at http://127.0.0.1:8000/.

✅ Step 3: Verifying the Server

After running the command, you should see output similar to this:

? View Code Example
// Console output indicating the server is running
Starting development server at http://127.0.0.1:8000/
Quit the server with CONTROL-C.

This confirms that the server is running successfully.

⛔ Step 4: Stopping the Server

To stop the development server, press Ctrl + C in the terminal.

? Explanation

  • Running the Server: Starts Django’s built-in server on port 8000.
  • Verifying the Server: Accessing the local URL confirms successful startup.
  • Stopping the Server: Terminates the server process safely.

? Interactive Example

Change the port number below and understand how Django binds the server to different ports.

? View Code Example
// Run the server on a custom port
python manage.py runserver 8080

Simulated Terminal Output:

Performing system checks...
System check identified no issues (0 silenced).
Starting development server at http://127.0.0.1:8080/
Quit the server with CONTROL-C.

? Use Cases

  • Testing views and templates locally
  • Debugging application logic
  • Learning Django project flow

✅ Tips & Best Practices

  • Use the development server only during development.
  • Restart the server if configuration changes are not reflected.
  • Use 0.0.0.0:8000 to expose the server on your local network.

? Try It Yourself

  • Run the server and open the default Django page in your browser.
  • Change the port number and observe the new URL.
  • Edit a template file and reload the page to see instant changes.