← Back to Chapters

Creating a Django Project

? Creating a Django Project

? Quick Overview

In this section, we learn how to create a new Django project using the django-admin startproject command. This command initializes the basic project structure required to start building a Django application.

? Key Concepts

  • Django projects act as containers for multiple applications.
  • The django-admin utility provides administrative commands.
  • The project structure separates configuration from application logic.

? Syntax / Theory

The startproject command creates a project directory with essential configuration files such as settings, URL routing, and WSGI configuration.

? View Code Example
// Create a new Django project using django-admin
django-admin startproject myproject

?️ Project Structure Overview

After running the command, Django generates the following directory structure:

? View Code Example
// Default Django project structure
myproject/
manage.py
myproject/
__init__.py
settings.py
urls.py
wsgi.py
  • manage.py: Command-line utility for administrative tasks.
  • settings.py: Configuration file for database, apps, middleware, and static files.
  • urls.py: URL routing configuration.
  • wsgi.py: Entry point for WSGI-compatible servers.

▶️ Running the Development Server

Navigate to the project directory and start the development server:

? View Code Example
// Navigate to project folder
cd myproject

// Start Django development server
python manage.py runserver

? Live Output / Explanation

? View Code Example
// Default server startup output
Starting development server at http://127.0.0.1:8000/
Quit the server with CONTROL-C.

Visiting http://127.0.0.1:8000/ in your browser displays the Django welcome page, confirming that the project setup is successful.

? Interactive Explanation

The Django development server automatically reloads when you change code files. Try stopping and restarting the server to observe how changes are reflected instantly.

$
 

? Use Cases

  • Building web applications with authentication and admin panels.
  • Developing REST APIs using Django REST Framework.
  • Rapid prototyping of backend systems.

✅ Tips & Best Practices

  • Always create projects inside a virtual environment.
  • Use meaningful project and app names.
  • Review settings.py carefully before production deployment.

? Try It Yourself

  • Create a new Django project with a custom name.
  • Run the development server and access it in your browser.
  • Edit urls.py and explore URL routing.