Lesson 11 of 60 – Run Development Server
18%

🚀 Run Django Development Server

In this lesson, you will learn how to run the Django development server, open your Django project in a browser, understand the server address, change the port, and stop the server.

Note: Django's development server is designed for local development and testing. It is not intended to be used as the production web server for a deployed application.

1. What Is the Development Server?

Django includes a lightweight development server that allows you to run your project locally while building and testing it.

You do not need to configure a separate web server just to start learning and developing a Django application.

2. Why Use the Development Server?

The development server makes it easy to test your Django application on your own computer.

  • Quickly start a Django project
  • Test views and URLs
  • Develop templates
  • Check application changes
  • Debug development problems

3. Make Sure Django Is Installed

Before starting the server, make sure Django is installed in your current Python environment.

python -m django --version

If the command displays a version number, Django is available.

4. Open the Project Directory

Open the terminal and move into the directory that contains manage.py.

For example:

cd MyDjangoProject

Django management commands are commonly executed from this directory.

5. Find manage.py

A basic Django project contains a manage.py file.

MyDjangoProject/
    manage.py
    myproject/
        settings.py
        urls.py
        asgi.py
        wsgi.py

Run the development server from the directory containing this file.

6. Start the Server

The basic command for starting Django's development server is:

python manage.py runserver

Django starts the local development server.

7. Server Address

After starting the server, Django normally displays a local address similar to:

http://127.0.0.1:8000/

Open this address in your web browser to view the project.

8. What Is 127.0.0.1?

127.0.0.1 is a loopback address that refers to your own computer.

When you open the Django development server at this address, the request is handled locally on your computer.

9. What Is Port 8000?

A port identifies a communication endpoint used by applications.

Django commonly starts its development server on port 8000.

http://127.0.0.1:8000/

10. Open Django in the Browser

After starting the server, open your preferred web browser.

Enter:

http://127.0.0.1:8000/

Django will display the default development page if the project is configured correctly.

11. Django Default Page

A newly created Django project can display Django's default welcome page when the development server is running successfully.

This confirms that the basic project can be started and accessed locally.

12. Auto Reload

During development, Django can automatically reload the development server when Python code changes are detected.

This makes development faster because you generally do not need to manually restart the server after every code change.

13. Change the Server Port

You can start the development server on a different port by providing the port number.

python manage.py runserver 8080

The server will then be available at a local address using port 8080.

14. Example with Port 5000

You can choose another available port, for example:

python manage.py runserver 5000

Then open:

http://127.0.0.1:5000/

15. Start the Server on a Specific Address

Django's development server can also be started with a specific address and port.

python manage.py runserver 127.0.0.1:8080

This starts the development server on the specified local address and port.

16. Access from Another Device

For certain development and testing situations, the server can be bound to an address that allows connections from other devices on the network.

python manage.py runserver 0.0.0.0:8000

Network configuration and firewall settings may affect whether another device can connect.

17. Development Server Is for Development

Django's development server is convenient for development and testing, but it is not designed to be a production deployment server.

Production deployments normally use a suitable production web server and application server configuration.

18. Server Terminal Output

When the server starts, the terminal displays information about the development server.

It can also display requests received by the application while you browse the site.

19. Browser Request

When you visit the local Django URL, your browser sends an HTTP request to the development server.

Django processes the request and returns an HTTP response.

20. URL and View Connection

Later, you will create URL patterns that connect URLs to views.

For example, a URL can be connected to a Python function that generates the response for that page.

urlpatterns = [
    ...
]

21. Stop the Development Server

To stop the development server, return to the terminal where it is running and press:

Ctrl + C

The server will stop and the terminal will return to the command prompt.

22. Start the Server Again

After stopping the server, you can start it again whenever you need it.

python manage.py runserver

Django will start the local server again.

23. Common Server Error

If the server cannot start because the port is already being used, choose another port.

python manage.py runserver 8080

This can allow you to continue development using another available port.

24. Check the Current Directory

If Django reports that manage.py cannot be found, you may be in the wrong directory.

Move to the directory containing manage.py and run the command again.

25. Activate the Virtual Environment

If Django is installed inside a virtual environment, make sure the environment is activated before running the project.

Windows:

venv\Scripts\activate

Linux/macOS:

source venv/bin/activate

26. Complete Windows Workflow

cd MyDjangoProject
venv\Scripts\activate
python manage.py runserver

Then open the local address shown in the terminal.

27. Complete Linux/macOS Workflow

cd MyDjangoProject
source venv/bin/activate
python manage.py runserver

Then open the local server address in your browser.

28. Basic Development Cycle

A simple Django development cycle is:

  1. Activate the virtual environment.
  2. Start the development server.
  3. Open the project in the browser.
  4. Write or modify code.
  5. Refresh the browser and test changes.
  6. Stop the server when finished.

29. Development Server Summary

The most commonly used command is:

python manage.py runserver

The default local address is commonly:

http://127.0.0.1:8000/

You can specify another port when needed.

30. Final Server Summary

Django's development server provides a convenient way to run and test your application locally.

python manage.py runserver

Open the local address in your browser, develop and test your application, and press Ctrl + C to stop the server.

You are now ready to learn how Django's project configuration works.

📌 Key Points

  • Use python manage.py runserver to start the development server.
  • The default development server commonly uses port 8000.
  • 127.0.0.1 refers to the local computer.
  • You can change the port using python manage.py runserver 8080.
  • Run the command from the directory containing manage.py.
  • Activate the correct virtual environment before running the project.
  • Press Ctrl + C to stop the development server.
  • The development server is intended for development and testing.

🧠 Quick Quiz

Question: Which command starts the Django development server?