Django Project Structure


Django Folder Layout Explained

When you create a Django project, several folders and files are generated. Each part has a purpose. Let’s break it down:

Assume you ran:

django-admin startproject webzone

Inside the webzone folder, you'll see something like this:

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

manage.py

This script is your control panel. It allows you to execute project commands like starting the server, running migrations, or managing apps.

Example usage:

python manage.py runserver

Outer webzone/ Folder

This is the main directory of your website configuration. It shares the name you gave the project. Think of it as the headquarters of settings and connectivity.


__init__.py

An empty file that makes the folder behave like a Python module. Without it, Python wouldn't treat it as importable code.


settings.py

This is your project's configuration hub.

Here you define:

  • Installed apps
  • Database info
  • Allowed hosts
  • Middleware
  • Static/media file settings
  • Template locations

You’ll frequently revisit this file as you expand your site.


urls.py

This is the routing map. It links web addresses to code that should handle them. When someone visits a page, Django checks here to know what to do.

You connect different pages and apps by registering paths.

Example:

path('admin/', admin.site.urls)

asgi.py

This file helps Django interact with ASGI-compatible servers, enabling modern communication styles like WebSockets. It’s more advanced but essential for real-time features.


wsgi.py

This script connects your app to WSGI-compatible platforms. It’s the standard interface for traditional servers like Gunicorn or uWSGI.


After Creating an App

Once you run:

python manage.py startapp blog

You’ll get another folder named blog with:

blog/ 
├── admin.py 
├── apps.py 
├── models.py 
├── tests.py 
├── views.py 
├── __init__.py 
├── migrations/ 

Each file helps handle different pieces of your new feature or section.


Prefer Learning by Watching?

Watch these YouTube tutorials to understand HTML Tutorial visually:

What You'll Learn:
  • 📌 How to Understand the Django Project Structure
  • 📌 How I Structure My Django Projects: Folders & Files 2022
Previous Next