Django has a reputation: "Powerful....but scary". You install a new project and suddenly youβre staring at files and folders like urls.py , wsgi.py , settings.py , apps , models and magic commands like migrate , all before even touching your django project.
Unlike Flaskβs simplicity in software architecture, Django provides a more structured, batteries-included framework that enforces clear separation of concerns and scalable architecture from the beginning.
This guide will demystify Djangoβs structure , why itβs designed this way , how each part plays a role in building your modern web applications.
1. Djangoβs Core Pattern: MVT != MVC
While most frameworks such as Laravel , Rails and even Flask extensions follow the classic MVC method (Model-View-Controllβ¦
Django has a reputation: "Powerful....but scary". You install a new project and suddenly youβre staring at files and folders like urls.py , wsgi.py , settings.py , apps , models and magic commands like migrate , all before even touching your django project.
Unlike Flaskβs simplicity in software architecture, Django provides a more structured, batteries-included framework that enforces clear separation of concerns and scalable architecture from the beginning.
This guide will demystify Djangoβs structure , why itβs designed this way , how each part plays a role in building your modern web applications.
1. Djangoβs Core Pattern: MVT != MVC
While most frameworks such as Laravel , Rails and even Flask extensions follow the classic MVC method (Model-View-Controller) design pattern, Django takes a slightly different by closely related approach called MVT (Model-View-Template)
Model defines the database structure and handles data interactions.
Template handles what the user sees such as UI rendering.
View processes logic, receives requests and return responses.
A simple flow of how Django works are shown below:
User requests -> URL -> View (Logic) -> Model (Data) -> Template (Display UI) -> Browser (Chrome , Opera etc)
This separation helps developers maintain clean, scalable code. Perfect for complex application with both user features and admin management!
2. Understanding Djangoβs multiple folder system
Letβs take a broader look at a Django project. A Django project is organized into two main types of folders, each serving a distinct purpose:
myproject/
β
βββ myproject/ # Project settings folder
β βββ __init__.py
β βββ settings.py # Configuration for DB, apps, middleware, templates
β βββ urls.py # URL routing for the whole project
β βββ wsgi.py / asgi.py# Server gateway interface
β
βββ myapp/ # Application folder
β βββ __init__.py
β βββ models.py # Database schema (used by both User & Admin)
β βββ views.py # Logic for User side
β βββ urls.py # Routes specific to this app
β βββ templates/ # HTML templates (User side)
β β βββ myapp/
β β βββ *.html
β βββ admin.py # Admin interface registration
β βββ forms.py # Forms for both User & Admin (optional)
β
βββ manage.py # Command-line utility for migrations, running server, etc.
βββ db.sqlite3 # Example database
2.1 myproject folder under myproject folder
Pretty weird concept right? Well , when you create a django project , you will begin with this command
django-admin startproject myproject
When you run this command , Django will create:
Outer folder (myproject/) β This is the project root or workspace. It holds everything related to your project, including your apps, the database, and manage.py. Think of it as the body of your project where all files live.
Inner folder (myproject/) β This is the project configuration folder. It contains all the settings and configuration files necessary to run your Django project, such as settings.py, urls.py, wsgi.py/asgi.py, and init.py. Think of it as the brain of your project.
Key files in the inner folder:
settings.py β Central place for configuration: databases, installed apps, middleware, templates, static files, and more.
urls.py β Central routing table for the project; can include app-specific URL patterns.
wsgi.py / asgi.py β Entry points for deploying your project on a web server.
init.py β Marks the folder as a Python package, enabling imports.
Think of the inner folder as the brain of the project, while the outer folder is the body or workspace that holds everything together.
2.2 myapp project in myproject folder
After creating a project, you create apps to handle different functionalities. For example:
python manage.py startapp myapp
Django creates the following structure:
myapp/
βββ __init__.py # Marks folder as a Python package
βββ admin.py # Register models to the admin interface
βββ apps.py # App configuration
βββ models.py # Database models for this app
βββ views.py # Logic / controllers for this app
βββ urls.py # App-specific routes (optional, you can create manually)
βββ migrations/ # Database migrations for this app
βββ templates/ # Optional HTML templates for this app
From this structure , Django suggests that :
- Apps are modular β Each app is self-contained.
- Reusable β You can plug an app into multiple projects.
- Organized β Each app has its own models, views, and templates.
- Example: You could have a blog app, a shop app, and a users app, all inside the same project.
2.3 How Project and App Work Together
myproject/is responsible for the global settings and routing.- Each app that you created contains its own models, views, templates, and logic.
- For example , a
blogapp that you created can register their routes in the project-level urls.py using include():
# myproject/urls.py
from django.contrib import admin
from django.urls import path, include
urlpatterns = [
path('admin/', admin.site.urls),
path('blog/', include('blog.urls')), # routes from the 'blog' app
]
- This modular design keeps your code organized and scalable, especially for larger projects.
2.4 Key Takeaways
Djangoβs architecture is designed based of separation of concerns.The project acts as the central configuration, holding global settings, URLs, and server interfaces, while each app is a self-contained module responsible for a specific feature, with its own models, views, and templates. This separation ensures that models handle data, views handle logic, and templates handle presentation, keeping the code organized and maintainable. The project + app structure dynamic also makes it easier to scale, as new functionality can be added by creating new apps without affecting existing ones.
Thank you for reading , look forward to more software engineering digest! Happy weekend :)