I am running a django application using celery. I get a strange error in the tasks.py file that looks like this:
from __future__ import absolute_import
from celery import shared_task
from django.contrib.auth.models import User
Here is the error:
django.core.exceptions.ImproperlyConfigured: The SECRET_KEY must not be empty.
SECRET_KEY is defined in my settings.py
import myproj.tasks
import djcelery
djcelery.setup_loader()
SECRET_KEY = '18730s9n9sjxamsuJSismxOIAmso102xjAs'
The application works fine if I comment on the import in the tasks.py file:
# from django.contrib.auth.models import User
and, more surprisingly, it works fine if I do the exact import in another file (e.g. testfile.py) in the same directory.
Why is this error occurring?
Edit: Here is my celery.py file
from __future__ import absolute_import
import os
from celery import Celery
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'myproj.settings')
from django.conf import settings
app = Celery('myproj')
app.config_from_object('django.conf:settings')
app.autodiscover_tasks(lambda: settings.INSTALLED_APPS)
source
share