Skip to content

amazipangu/docker-django

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

41 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Dockerize Django Environment

Specification

How to use

  1. Build your Docker environment
docker-compose build
  1. Create the Django project using the docker-compose command.
docker-compose run web django-admin.py startproject yourproject .
  1. 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,
    }
}
  1. In web/yourproject/settings.py, add the line at the bottom of it.
 STATIC_ROOT = STATIC_ROOT = os.path.join(BASE_DIR, 'static')
  1. Install Admin app. In web/yourproject/settings.py, add line django.contrib.admin
INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
]
  1. Run the docker-compose up command again
sh bin/container_start.sh
  1. Go ahead, create your app!
docker-compose exec web python manage.py startapp yourapp
  1. Initilize your database
docker-compose exec web python manage.py migrate
  1. Enable Model
  • Define your model class in yourapps/models.py

  • Add line yourapps.apps.YourappsConfig in web/app/settings.py of INSTALLED_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
  1. Initilize Django admin
docker-compose exec -it web python manage.py createsuperuser
  1. Collecting staticfiles
docker-compose run web python manage.py collectstatic --noinput

About

Dockerize Django Environment

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published