- Install pyenv
- Install the configured python version (3.12.7) using pyenv by running the command
- For Mac/Linux
pyenv install
- For Windows
pyenv install 3.11.5
- For Mac/Linux
- Create virtual environment by running the command
- For Mac/Linux
pyenv virtualenv 3.11.5 venv
- For Windows
python -m pip install virtualenv python -m virtualenv venv
- For Mac/Linux
- Activate the virtual environment by running the command
- For Mac/Linux
pyenv activate venv
- For Windows
.\venv\Scripts\activate
- For Mac/Linux
- Install the project dependencies by running the command
python -m pip install -r requirements.txt
- Create a
.env
file for environment variables:- Copy the example environment file:
cp .env.example .env
- Edit the
.env
file and update the values according to your setup:SECRET_KEY
: Generate a unique secret key for DjangoMONGODB_URI
: MongoDB connection string (default:mongodb://localhost:27017
)DB_NAME
: Your database nameGOOGLE_OAUTH_CLIENT_ID
andGOOGLE_OAUTH_CLIENT_SECRET
: OAuth credentials for Google authenticationPRIVATE_KEY
andPUBLIC_KEY
: Generate RSA key pairs for JWT token signing- Other settings can be left as default for local development
- Copy the example environment file:
- Install docker and docker compose
- Start MongoDB using docker
docker compose up -d db
- Start the development server by running the command
python manage.py runserver
- Go to http://127.0.0.1:8000/v1/health API to make sure the server it up. You should see this response
{ "status": "UP", "components": { "db": { "status": "UP" } } }
- Install docker and docker compose
- Start Django application and MongoDB using docker
docker compose up -d
- Go to http://127.0.0.1:8000/v1/health API to make sure the server it up. You should see this response
{ "status": "UP" }
- On making changes to code and saving, live reload will work in this case as well
- To run the tests, run the following command
python manage.py test
- To check test coverage, run the following command
coverage run --source='.' manage.py test coverage report
- To run the formatter
ruff format
- To run lint check
ruff check
- To fix lint issues
ruff check --fix
- VS Code with Python extension installed
- Docker and docker-compose
-
Start the application with debug mode:
python manage.py runserver_debug 0.0.0.0:8000
-
Available debug options:
# Basic debug mode (default debug port 5678) python manage.py runserver_debug 0.0.0.0:8000 # Custom debug port python manage.py runserver_debug 0.0.0.0:8000 --debug-port 5679 # Wait for debugger before starting (useful for debugging startup code) python manage.py runserver_debug 0.0.0.0:8000 --wait-for-client
-
Attach VS Code debugger:
- Press
F5
or go toRun > Start Debugging
- Select
Python: Remote Attach (Django in Docker)
from the dropdown - Set breakpoints in your Python code
- Make requests to trigger the breakpoints
- Press
- Debug server port: 5678 (configurable)
- Path mapping: Local code mapped to container paths
- Django mode: Special Django debugging features enabled
- Hot reload: Code changes reflected immediately
- Variable inspection: Full debugging capabilities in VS Code
- If port 5678 is in use, specify a different port with
--debug-port
- Ensure VS Code Python extension is installed
- Check that breakpoints are set in the correct files
- Verify the debug server shows "Debug server listening on port 5678"