Introduction
If youโre new to Django, one of the most confusing things at the beginning is its project structure.
After running django-admin startproject, you suddenly see files like:
settings.pyurls.pywsgi.pyasgi.py
And folders inside folders ๐ตโ๐ซ
In this article, weโll break down Djangoโs project structure in a simple, practical way, so you understand:
- What each file does
- Why Django is structured this way
- How this structure helps you build scalable applications
By the end, Djangoโs structure will feel logical, not scary.
Creating a Django Project (Quick Recap)
Letโs start fresh:
django-admin startproject myproject
cd myproject
Your folder structure will look like this:
myproject/
โโโ manage.py
โโโ myproject/
โโโ __init__.py
โโโ settings.py
โโโ urls.py
โโโ asgi.py
โโโ wsgi.py
Now letโs understand each part one by one.
1๏ธโฃ manage.py โ The Command Center
# manage.py
What it does:
- Helps you interact with your Django project
- Runs the development server
- Executes migrations
- Creates apps, superusers, and more
Common commands:
python manage.py runserver
python manage.py makemigrations
python manage.py migrate
python manage.py createsuperuser
๐ Think of manage.py as the remote control of your Django project.
2๏ธโฃ The Inner Project Folder (myproject/)
This inner folder contains the core configuration of your project.
Important:
- The outer folder is just a container
- The inner folder is the actual Django project
3๏ธโฃ settings.py โ Project Configuration Brain ๐ง
This is one of the most important files in Django.
What lives here:
- Installed apps
- Database configuration
- Middleware
- Templates
- Static & media files
- Security settings
Example:
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'blog',
]
๐ Any time something โdoesnโt workโ, settings.py is usually involved.
4๏ธโฃ urls.py โ Traffic Controller ๐ฆ
This file decides:
โWhich URL goes to which view?โ
Example:
from django.urls import path
from . import views
urlpatterns = [
path('', views.home, name='home'),
]
Key idea:
- URLs map โ Views
- Clean URL structure = better UX & SEO
๐ Think of urls.py as Google Maps for your website.
5๏ธโฃ wsgi.py โ Production Entry Point
WSGI stands for Web Server Gateway Interface.
Used when:
- Deploying Django to production
- Running with Gunicorn or uWSGI
You usually donโt touch this file, but itโs critical for deployment.
๐ Without wsgi.py, Django canโt talk to your server.
6๏ธโฃ asgi.py โ Async & Real-Time Support
ASGI is the modern version of WSGI.
Used for:
- WebSockets
- Real-time apps
- Django Channels
If you build:
- Chat apps
- Notifications
- Live dashboards
๐ asgi.py becomes very important.
7๏ธโฃ init.py โ Python Package Marker
This file tells Python:
โThis folder is a package.โ
Most of the time, you wonโt modify itโbut itโs required.
Apps vs Projects (Very Important Concept)
โ Project
- Entire website
- Configuration & settings
โ App
- A feature or module
- Reusable component
Example apps:
blogaccountsdashboardpayments
Create an app:
python manage.py startapp blog
App structure:
blog/
โโโ admin.py
โโโ apps.py
โโโ models.py
โโโ views.py
โโโ tests.py
โโโ migrations/
๐ One project = many apps
This is what makes Django clean and scalable.
Why Django Enforces This Structure
Djangoโs structure helps you:
- Separate concerns
- Avoid spaghetti code
- Scale teams and features
- Maintain large projects easily
This is why Django works well for:
- SaaS platforms
- Content sites
- Admin-heavy systems
- Enterprise applications
Common Beginner Mistakes โ
โ Putting everything in one app
โ Editing settings.py randomly
โ Not understanding URL routing
โ Renaming core files
๐ Learn the structure once, and Django becomes much easier.
Best Practices โ
โ Keep apps small and focused
โ Use meaningful app names
โ Separate settings for dev & prod
โ Organize templates by app
Final Thoughts
Djangoโs project structure may look complex at first, but itโs actually one of its biggest strengths.
Once you understand:
- Projects vs Apps
- URLs โ Views โ Templates
- Configuration flow
๐ Django becomes predictable, scalable, and enjoyable to work with.