Django Project Structure

When you create a Django project, Django automatically generates a set of files and folders. Understanding this structure is important because each file has a specific role in the application.

Creating a Django Project

django-admin startproject myproject

Project Structure:

myproject/
│
├── manage.py
│
└── myproject/
    ├── __init__.py
    ├── settings.py
    ├── urls.py
    ├── asgi.py
    └── wsgi.py

manage.py

This is the command-line utility used to interact with your Django project.

Common commands:

python manage.py runserver
python manage.py makemigrations
python manage.py migrate
python manage.py createsuperuser

init.py

This file tells Python that the directory should be treated as a Python package.

Most of the time, you won’t need to modify this file.

settings.py

This is the main configuration file of your Django project.

It contains:

  • Installed applications
  • Database configuration
  • Middleware
  • Templates configuration
  • Static files settings
  • Security settings

Example:

INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
]

urls.py

This file defines the URL routes for the project.

Example:

from django.contrib import admin
from django.urls import path

urlpatterns = [
    path('admin/', admin.site.urls),
]

When a user visits a URL, Django checks this file to determine which view should handle the request.

wsgi.py

WSGI stands for Web Server Gateway Interface.

This file is used when deploying Django applications on production servers such as Gunicorn.

It acts as a bridge between the web server and your Django application.

asgi.py

ASGI stands for Asynchronous Server Gateway Interface.

It is used for asynchronous features such as:

  • WebSockets
  • Real-time applications
  • Async views

ASGI is the modern successor to WSGI for handling asynchronous requests.

Difference Between Project and App

Project

A project is the entire Django website.

Examples:

  • E-commerce Website
  • LMS System
  • Blog Website

App

An app is a module that performs a specific function.

Examples:

  • User Management App
  • Product App
  • Orders App
  • Blog App

One Django project can contain multiple apps.

Example:

Ecommerce Project
│
├── Users App
├── Products App
├── Orders App
└── Payments App

Key Takeaway

  • manage.py → Executes Django commands.
  • settings.py → Project configuration.
  • urls.py → URL routing.
  • wsgi.py → Production deployment interface.
  • asgi.py → Async application interface.
  • Project = Complete website.
  • App = Specific functionality within a project.