0
0
DjangoHow-ToBeginner · 3 min read

How to Run Django Server: Simple Steps to Start Your Project

To run the Django server, open your terminal, navigate to your project folder, and run python manage.py runserver. This command starts the development server, usually accessible at http://127.0.0.1:8000/ in your browser.
📐

Syntax

The basic command to start the Django development server is python manage.py runserver. You can optionally specify the IP address and port like python manage.py runserver 0.0.0.0:8080.

  • python: Runs Python interpreter.
  • manage.py: Django's command-line utility for project tasks.
  • runserver: Command to start the development server.
  • IP:Port (optional): Defines where the server listens; default is 127.0.0.1:8000.
bash
python manage.py runserver
python manage.py runserver 0.0.0.0:8080
💻

Example

This example shows how to start the Django server on the default address and port. After running the command, you can open your browser and visit http://127.0.0.1:8000/ to see your Django project running.

bash
cd my_django_project
python manage.py runserver
Output
Watching for file changes with StatReloader Performing system checks... System check identified no issues (0 silenced). April 27, 2024 - 10:00:00 Django version 4.2, using settings 'my_django_project.settings' Starting development server at http://127.0.0.1:8000/ Quit the server with CONTROL-C.
⚠️

Common Pitfalls

Common mistakes when running the Django server include:

  • Running the command outside the project folder where manage.py is located.
  • Not activating the virtual environment with Django installed.
  • Trying to use a port already in use, causing an error.
  • Forgetting to apply migrations before running the server, which can cause errors on page load.

Always ensure you are in the correct directory and your environment is set up.

bash
cd wrong_folder
python manage.py runserver

# Correct way:
cd my_django_project
python manage.py runserver
📊

Quick Reference

Summary tips for running the Django server:

  • Use python manage.py runserver inside your project folder.
  • Specify IP and port if needed, e.g., python manage.py runserver 0.0.0.0:8000.
  • Activate your virtual environment before running the server.
  • Apply migrations with python manage.py migrate before starting.
  • Stop the server anytime with CTRL+C.

Key Takeaways

Run the server with python manage.py runserver inside your Django project folder.
You can specify a custom IP and port like python manage.py runserver 0.0.0.0:8080.
Always activate your virtual environment before running the server.
Apply migrations first using python manage.py migrate to avoid errors.
Stop the server anytime with CTRL+C in the terminal.