A Django project with PostgreSQL database integration and RESTful API endpoints.
- Django 5.2.4 with Django REST Framework
- PostgreSQL database backend
- Blog application with API endpoints
- CORS support for cross-origin requests
- OpenAPI/Swagger documentation with drf-spectacular
- Environment-based configuration
- Docker Compose setup for development
- Python 3.12+
- PostgreSQL
- Docker and Docker Compose (optional, for containerized development)
- Clone the repository:
git clone git@github.com:marcus888-techstack/test-django-db.git
cd test-django-db- Create a virtual environment:
python -m venv .venv
source .venv/bin/activate # On Windows: .venv\Scripts\activate- Install dependencies:
pip install -e .- Set up environment variables:
cp .env.example .env
# Edit .env with your actual configuration- Run database migrations:
python manage.py migrate- Create a superuser (optional):
python manage.py createsuperuser- Run the development server:
python manage.py runserverAlternatively, you can use Docker Compose:
docker-compose up -dThis will start both the Django application and PostgreSQL database in containers.
Copy .env.example to .env and configure:
SECRET_KEY: Django secret key (generate a new one for production)DEBUG: Set toFalsein productionALLOWED_HOSTS: Comma-separated list of allowed hostsDB_NAME: PostgreSQL database nameDB_USER: PostgreSQL usernameDB_PASSWORD: PostgreSQL passwordDB_HOST: Database host (usedbfor Docker,localhostfor local)DB_PORT: Database port (default: 5432)
Once the server is running, you can access:
- API endpoints:
http://localhost:8000/api/ - Swagger UI:
http://localhost:8000/api/schema/swagger-ui/ - ReDoc:
http://localhost:8000/api/schema/redoc/
test-django-db/
├── blog/ # Blog application
│ ├── api/ # API views and serializers
│ ├── migrations/ # Database migrations
│ └── models.py # Data models
├── myproject/ # Project configuration
│ ├── settings.py # Django settings
│ ├── urls.py # URL configuration
│ └── wsgi.py # WSGI configuration
├── .env.example # Environment variables template
├── docker-compose.yml # Docker Compose configuration
├── manage.py # Django management script
└── pyproject.toml # Project dependencies
To install python-dotenv (required for environment variables):
pip install python-dotenvRun tests with:
python manage.py testThis project is licensed under the MIT License.