The Django Celery Redis github repo shows a full Django project leveraging the results of this blog post tutorial and this sample project.
git clone https://github.com/codingforentrepreneurs/Django-Celery-Redis
cd Django-Celery-Redis
macos/linux
python3 -m venv venv
source venv/bin/activate
windows
c:\Python311\python.exe -m venv venv
.\venv\Scripts\activate
Install requirements
python -m pip install pip --upgrade
python -m pip install -r requirements.txt
Run a local redis instance via Docker Compose
docker compose -f compose.yaml up -d
This will give us redis://localhost:6170
Create .env
in src/.env
with:
CELERY_BROKER_REDIS_URL="redis://localhost:6170"
DEBUG=True
Navigate into your Django root:
cd src/
ls
You should see at least cfehome/
and manage.py
.
Run your project in 2 terminals:
python manage.py runserver
celery -A cfehome worker --beat
Verify it's working:
python manage.py shell
then import placeholder tasks
from movies.tasks import add
add.delay(1,3)
The result should be printed in the celery -A cfehome worker --beat
terminal.