Best Django Project Setup
Download Boilerplate Code
py -m virtualenv env && env\Scripts\activate
pip install django pillow django-allauth django-environ django-crispy-forms psycopg2-binary django-redis gunicorn
Custom Configuration
Don't Copy
settings.py
INSTALLED_APPS = [
#Third Party Apps
    'django.contrib.sites',
    'allauth',
    'allauth.account',
    'allauth.socialaccount',
#Apps
    'appname.apps.AppnameConfig',
]

Django Allauth Config path('accounts/', include('allauth.urls')),
LOGIN_REDIRECT_URL = 'home'
ACCOUNT_LOGOUT_REDIRECT = 'home'
SITE_ID = 1
EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend'
ACCOUNT_EMAIL_VERIFICATION = 'none'
ACCOUNT_SESSION_REMEMBER = True
ACCOUNT_USER_MODEL_USERNAME_FIELD = None
ACCOUNT_USERNAME_REQUIRED = False  
ACCOUNT_AUTHENTICATION_METHOD = 'email'  
ACCOUNT_EMAIL_REQUIRED = True  
ACCOUNT_UNIQUE_EMAIL = True  
AUTHENTICATION_BACKENDS = [
    'django.contrib.auth.backends.ModelBackend',
    'allauth.account.auth_backends.AuthenticationBackend',
]

Postgres Database use Environments
DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.postgresql',
        'NAME': 'postgres',
        'USER': 'postgres',
        'PASSWORD': 'postgres',
        'HOST': 'db',
        'PORT': 5432,
    }
}
AUTH_USER_MODEL= 'appname.CustomUser'

Static files (CSS, JavaScript, Images)
STATIC_URL = '/static/'
MEDIA_URL = '/media/'
STATIC_ROOT = BASE_DIR / 'static_root'
MEDIA_ROOT = BASE_DIR / 'media_root'
STATICFILES_DIRS = [ BASE_DIR / 'static'
]
STATICFILES_FINDERS = [
    "django.contrib.staticfiles.finders.FileSystemFinder",
    "django.contrib.staticfiles.finders.AppDirectoriesFinder",
]
Containerizing Django Applications
Don't Copy
Nginx Dockerfile
FROM nginx:1.19.0-alpine
RUN rm /etc/nginx/conf.d/default.conf
COPY nginx.conf /etc/nginx/conf.d
Nginx Conf
upstream config {
    server web:8000;
}
server {
    listen 80;
    location / {
        proxy_pass http://config;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header Host $host;
        proxy_redirect off;
    }    
    location /static/ {
	     alias /static/;
	}
}
Writing a Dockerfile
FROM python:3.9-slim
# Set environment variables
ENV PYTHONDONTWRITEBYTECODE 1
ENV PYTHONUNBUFFERED 1
# Set work directory
WORKDIR /code
# Install dependencies
COPY Pipfile Pipfile.lock /code/
RUN pip install pipenv && pipenv install --system
# Copy project
COPY . /code/
Docker Compose File
version: '3.8'
services:
  web:
    build: .
    #command: python /code/manage.py runserver 0.0.0.0:8000
    command: gunicorn config.wsgi -b 0.0.0.0:8000
    volumes: 
      - .:/code
      #- static_volume:/static
    ports:
      - 8000:8000
    depends_on: 
      - db
  db:
    image: postgres:11
    environment:
      - "POSTGRES_HOST_AUTH_METHOD=trust"
  nginx:
    build: ./nginx
    volumes:  
      - static_volume:/static
    ports:
      - 80:80
    depends_on:
      - web
volumes:
  static_volume: