Skip to content

marcus888-techstack/test-django-db

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Test Django DB

A Django project with PostgreSQL database integration and RESTful API endpoints.

Features

  • 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

Requirements

  • Python 3.12+
  • PostgreSQL
  • Docker and Docker Compose (optional, for containerized development)

Installation

  1. Clone the repository:
git clone git@github.com:marcus888-techstack/test-django-db.git
cd test-django-db
  1. Create a virtual environment:
python -m venv .venv
source .venv/bin/activate  # On Windows: .venv\Scripts\activate
  1. Install dependencies:
pip install -e .
  1. Set up environment variables:
cp .env.example .env
# Edit .env with your actual configuration
  1. Run database migrations:
python manage.py migrate
  1. Create a superuser (optional):
python manage.py createsuperuser
  1. Run the development server:
python manage.py runserver

Docker Setup

Alternatively, you can use Docker Compose:

docker-compose up -d

This will start both the Django application and PostgreSQL database in containers.

Environment Variables

Copy .env.example to .env and configure:

  • SECRET_KEY: Django secret key (generate a new one for production)
  • DEBUG: Set to False in production
  • ALLOWED_HOSTS: Comma-separated list of allowed hosts
  • DB_NAME: PostgreSQL database name
  • DB_USER: PostgreSQL username
  • DB_PASSWORD: PostgreSQL password
  • DB_HOST: Database host (use db for Docker, localhost for local)
  • DB_PORT: Database port (default: 5432)

API Documentation

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/

Project Structure

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

Development

To install python-dotenv (required for environment variables):

pip install python-dotenv

Testing

Run tests with:

python manage.py test

License

This project is licensed under the MIT License.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages