Lesson 2 / 26
A Django Project and App
startproject and startapp.
Projects contain apps
A Django project holds settings, root URLs and the ASGI/WSGI entry points; apps are reusable components (catalog, orders, accounts), each with models, views, tests and migrations. Create them with django-admin startproject and python manage.py startapp, then add the app to INSTALLED_APPS. manage.py runs commands: runserver, makemigrations, migrate, shell, test, createsuperuser.
Creating the demo project, run
I ran this with Django 6.1.1 and Python 3.12 in a demo project (shopsite with a catalog app) using SQLite. The generated files: a shopsite project package (settings, urls, asgi, wsgi) and a catalog app (models, views, admin, apps, tests), plus manage.py.
django-admin startproject shopsite .
python manage.py startapp catalog
find . -name "*.py" | sort
Output:
./catalog/admin.py ./catalog/apps.py ./catalog/__init__.py ./catalog/models.py ./catalog/tests.py ./catalog/views.py ./manage.py ./shopsite/asgi.py ./shopsite/__init__.py ./shopsite/settings.py ./shopsite/urls.py ./shopsite/wsgi.py
Split settings per environment
Read secrets and environment-specific values from environment variables rather than editing settings.py per server.
Quick check: What must you do after startapp for Django to use the app?
- Add it to INSTALLED_APPS
- Restart the computer
- Rename manage.py
- Nothing
Answer
Add it to INSTALLED_APPS — Apps are registered in settings.