A Django project template with Docker and PostgreSQL setup, created using django-admin startproject.
- Django 4.2.26 (created with django-admin startproject)
- PostgreSQL 15
- Docker & Docker Compose
- Whitenoise for static files
- Environment variables configuration with python-decouple
- Ready-to-use templates
- All Django code organized in
/appdirectory
- Docker
- Docker Compose
# Copy environment variables
cp .env.example .env
# Edit .env file and update the SECRET_KEY and other settings as needed# Build and start containers
docker-compose up --build
# The application will be available at http://localhost:8000# In a new terminal, run migrations
docker-compose exec web python manage.py migrate
# Create a superuser for admin access
docker-compose exec web python manage.py createsuperuser# Start containers
docker-compose up
# Start containers in detached mode
docker-compose up -d
# Stop containers
docker-compose down
# View logs
docker-compose logs -f web
# Run Django commands
docker-compose exec web python manage.py <command>
# Run migrations
docker-compose exec web python manage.py migrate
# Create superuser
docker-compose exec web python manage.py createsuperuser
# Collect static files
docker-compose exec web python manage.py collectstatic
# Access Django shell
docker-compose exec web python manage.py shell
# Access PostgreSQL
docker-compose exec db psql -U django_user -d django_db.
├── app/ # Django application directory
│ ├── config/ # Django configuration (created by startproject)
│ │ ├── __init__.py
│ │ ├── settings.py # Django settings (configured for PostgreSQL)
│ │ ├── urls.py # URL configuration
│ │ ├── wsgi.py # WSGI configuration
│ │ └── asgi.py # ASGI configuration
│ ├── templates/ # HTML templates
│ │ └── home.html
│ ├── static/ # Static files (CSS, JS, images)
│ └── manage.py # Django management script
├── Dockerfile # Docker configuration
├── docker-compose.yml # Docker Compose configuration
├── requirements.txt # Python dependencies
├── .env.example # Environment variables template
├── .gitignore # Git ignore file
└── README.md # This file
The project uses volume mounting, so any changes you make to the code will be reflected immediately without rebuilding the container.
Access the admin panel at http://localhost:8000/admin after creating a superuser.
Key environment variables (see .env.example):
DEBUG: Enable/disable debug modeSECRET_KEY: Django secret keyDB_NAME: Database nameDB_USER: Database userDB_PASSWORD: Database passwordDB_HOST: Database hostDB_PORT: Database port
To create a new Django app within the project:
# Enter the Django container
docker-compose exec web bash
# Create a new app (this will create it in /code directory inside container)
python manage.py startapp myapp
# Exit the container
exitThe new app will be created in the app/ directory. Remember to add it to INSTALLED_APPS in app/config/settings.py:
INSTALLED_APPS = [
"django.contrib.admin",
"django.contrib.auth",
"django.contrib.contenttypes",
"django.contrib.sessions",
"django.contrib.messages",
"django.contrib.staticfiles",
"myapp", # Add your new app here
]For production:
- Set
DEBUG=Falsein .env - Update
SECRET_KEYwith a secure random key - Configure
ALLOWED_HOSTSproperly - Use a production-grade WSGI server (gunicorn is included)
- Set up proper static file serving
- Configure database backups
- Use environment-specific docker-compose files
MIT