Python-Django-Poetry-Starter
Requirements:
- Python (^3.12)
- Django (^5.1.1)
- Psycopg (^3.2.2)
- Uvicorn (^0.32.0)
- Gunicorn (^23.0.0)
- Django-cors-headers (^4.4.0)
- Django-rest-framework (^3.15.2)
- Pillow (^11.0.0)
- Drf-spectacular (^0.27.2)
- Python-dotenv(^1.0.1)
- Django-rest-framework-simplejwt(^5.3.1)
Dev
- Mypy
- AutoPep8
- Isort
- Pytest
- Pytest-cov
- Pytest-django
Poetry workflow
More info about Poetry
1) Install poetry package manager or read official manual
pipx install poetry
2) After install all project dependencies (.venv creates in project folder)
poetry install
3) Activate local venv with poetry
poetry shell
4) Run your app
python manage.py runserver 8080
5) How deactivate poetry shell in terminal
deactivate
Poetry scripts
1) Start (runserver with pre-installed settings)
poetry run start
2) Migrate (confirm migrations)
poetry run migrate
3) Migrations (model migrations)
poetry run migrations
4) Static (collectstatic)
poetry run static
5) Generate_key (generate django secret_key and save into .env.secret)
poetry run generate_key
6) Generate_jwt (generate django jwt_key and save into .env.secret)
poetry run generate_jwt
Poetry dependecies workflow
1) Show current env dependencies and latest packages
poetry show -l
2) Update all dependencies and write poetry.lock
poetry update
3) Update installed package in latest version (group optional)
poetry add <pakage_name>@latest
4) Write poetry.lock into legasy requirements.txt
poetry export -o requirements.txt
Docker workflow
Install docker on your local mashine. Use docker compose build for local fullstack project.
Django workflow
More info about Django
How create new django-app in project?
1) Goto root project folder
cd src
2) Create new django-app folder (empty folder for new app)
mkdir apps/<django-app-name>
3) Create new django-app in your pre-exist apps/django-app-name
python manage.py startapp <django-app-name> ./apps/<django-app-name>
4) Create new django-app in your pre-exist app folder (using django-admin)
django-admin startapp <django-app-name> ./src/apps/<django-app-name>
Django generate SECRET_KEY (CLI mode)
1) Goto root project folder
cd src
2) Paste into terminal and run (create .env.secret if non exist with generated secret key)
python -c 'from django.core.management.utils import get_random_secret_key; f = open(".env.secret", "w"); key = get_random_secret_key(); f.write(f"API_SECRET_KEY={key}"); f.close(); print("Django: SECRET_KEY generated")'
Django generate SECRET_KEY with poetry (recommended)
1) Install all modules with poetry
poetry install
2) Run generate_key script with poetry (create .env.secret or append if exists with API_SECRET_KEY)
poetry run generate_key
Django generate JWT_KEY with poetry (recommended)
1) Install all modules with poetry
poetry install
2) Run generate_jwt script with poetry (create .env.secret or append if exists with JWT_SECRET_KEY)
poetry run generate_jwt