Skip to content

lihuacai168/django-ninja-demo

Repository files navigation

Github Actions codecov Dynamic YAML Badge

Key Features

  • 🛡️ High Coverage: Rigorous unit tests for robust codebase assurance.
  • 😊 Fast CRUD Router: Quick and easy create, read, update, and delete operations.
  • Uniform API: Consistent responses throughout the service.
  • 🔍 Trace IDs: Simplified issue tracking with trace IDs in logs fast_curd stand_response response_trace_id log_trace_id

Quick start

Clone code

git clone https://github.com/lihuacai168/django-ninja-demo.git

Docker-compose

# set env
cp .env.example .env

Make sure db have migrated

# start app
docker-compose -f docker-compose-without-db.yml --env-file=${PWD}/.env up --build

Local Dev

Create virtualenv

python3 -m venv venv

Activate virtualenv

source venv/bin/activate

Install dependencies

cd django-ninja-demo && pip install -r requirements.txt

Migrate db

python manage.py migrate

Start app

python manage.py runserver localhost:8000

Open api docs open in browser

Obtain access token

img.png img_1.png

Authorize and request API

img.png img_1.png

Celery

Config celery broker

# setting.py
broker_url = "redis://127.0.0.1:6379/0"

Run celery worker

# start celery worker, using command line
python -m celery -A apidemo.celery_config worker -l INFO 

PyCharm run_celery_worker_configuration

pycharm_run_celery_worker_configuration

Run celery beat

# start celery beat, using command line
python -m celery -A apidemo.celery_config beat -l DEBUG 

PyCharm run_celery_beat_configuration

pycharm_run_celery_beat_configuration