Adding Celery to your project

You have to provide a configuration for the Celery instance. Create a new file next to the settings.py file of myshop and name it celery.py. This file will contain the Celery configuration for your project. Add the following code to it:

import osfrom celery import Celery# set the default Django settings module for the 'celery' program.os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'myshop.settings')app = Celery('myshop')app.config_from_object('django.conf:settings', namespace='CELERY')app.autodiscover_tasks()

In this code, we do the following:

  1. We set the DJANGO_SETTINGS_MODULE variable for the Celery command-line program.
  2. We create an instance of the application with app = Celery('myshop').
  3. We load any custom ...

Get Django 2 by Example now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.