One project can contain many applications. An application can be reused in another project.
The Difference
Project — the entire site configuration: settings.py, the main urls.py, wsgi.py.
Application — a modular component with a specific purpose: models, views, urls, templates.
mysite/ ← PROJECT
├── manage.py
├── mysite/
│ ├── settings.py
│ └── urls.py
├── blog/ ← APPLICATION
│ ├── models.py
│ └── views.py
└── shop/ ← APPLICATION
├── models.py
└── views.py
One project can contain many applications. An application can be reused in another project.
Creating an Application
python manage.py startapp tasks
INSTALLED_APPS — Registration
Every application must be listed in INSTALLED_APPS; otherwise Django will not recognize it:
# settings.py
INSTALLED_APPS = [
# Built-in Django applications
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
# Third-party
'rest_framework',
'crispy_forms',
# Your applications
'tasks',
'blog',
'shop',
]
AppConfig — Application Configuration
# tasks/apps.py
from django.apps import AppConfig
class TasksConfig(AppConfig):
default_auto_field = 'django.db.models.BigAutoField'
name = 'tasks'
verbose_name = 'Tasks'
You can explicitly reference it in INSTALLED_APPS:
INSTALLED_APPS = [
'tasks.apps.TasksConfig', # instead of just 'tasks'
]
When to Extract a Separate Application
- Users and authentication →
accounts - Blog with articles →
blog - Cart and orders →
shop - API →
api
Rule of thumb: if the functionality can be described with a single noun, it is a candidate for a separate application.
💬 Comments (0)
No comments yet
Be the first to share your opinion about this article!