- WSGI
- HTTP server
- Database
- Build your Docker environment
docker-compose build
- Create the Django project using the docker-compose command.
docker-compose run web django-admin.py startproject yourproject .
- In your project directory, edit the yourproject/settings.py file.
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql',
'NAME': 'your_db_name',
'USER': 'your_db_user',
'PASSWORD': 'your_db_password',
'HOST': 'db',
'PORT': 5432,
}
}
- In
web/yourproject/settings.py
, add the line at the bottom of it.
STATIC_ROOT = STATIC_ROOT = os.path.join(BASE_DIR, 'static')
- Install Admin app. In
web/yourproject/settings.py
, add linedjango.contrib.admin
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
]
- Run the
docker-compose up
command again
sh bin/container_start.sh
- Go ahead, create your app!
docker-compose exec web python manage.py startapp yourapp
- Initilize your database
docker-compose exec web python manage.py migrate
- Enable
Model
-
Define your model class in
yourapps/models.py
-
Add line
yourapps.apps.YourappsConfig
inweb/app/settings.py
ofINSTALLED_APPS
INSTALLED_APPS = [ 'yourapps.apps.YourappsConfig', 'django.contrib.admin', 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.messages', 'django.contrib.staticfiles', ]
-
do migrations
docker exec web python manage.py makemigrations yourapps
- Initilize Django admin
docker-compose exec -it web python manage.py createsuperuser
- Collecting staticfiles
docker-compose run web python manage.py collectstatic --noinput