Skip to content

Instantly share code, notes, and snippets.

@codingforentrepreneurs
Last active March 4, 2024 19:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save codingforentrepreneurs/546c72965eb4046301bed8d6a38dc3f8 to your computer and use it in GitHub Desktop.
Save codingforentrepreneurs/546c72965eb4046301bed8d6a38dc3f8 to your computer and use it in GitHub Desktop.
How to run a sample Django x Celery project

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment