1π
The error message clearly states:
django.core.exceptions.ImproperlyConfigured: Requested settings, but settings are not configured. You must either define the environment variable
DJANGO_SETTINGS_MODULE or call settings.configure() before accessing settings.
This means that you either have to define a environment variable called DJANGO_SETTINGS_MODULE
or call the method settings.configure
in your code before you access the settings.
I would suggest to set the environment variable DJANGO_SETTINGS_MODULE
.
Documentation: https://docs.djangoproject.com/en/1.11/topics/settings/#designating-the-settings
3π
The best practice when using Django with Celery is to have your Celery app configured by Djangoβs settings file.
http://docs.celeryproject.org/en/latest/django/first-steps-with-django.html
from __future__ import absolute_import, unicode_literals
import os
from celery import Celery
# set the default Django settings module for the 'celery' program.
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'proj.settings')
app = Celery('proj')
# Using a string here means the worker don't have to serialize
# the configuration object to child processes.
# - namespace='CELERY' means all celery-related configuration keys
# should have a `CELERY_` prefix.
app.config_from_object('django.conf:settings', namespace='CELERY')
# Load task modules from all registered Django app configs.
app.autodiscover_tasks()
This uses app.config_from_object()
and also sets up your project to automatically discover tasks from tasks.py
files in your Django installed apps.
- [Django]-PyCharm doesn't recognise my VirtualEnv installed modules
- [Django]-Integrating Django with Amazon's Database 'SimpleDB'
- [Django]-Django with django-nose: two identical settings files with different behavior in running test command
- [Django]-Django crispy-forms β Custom button
- [Django]-Upgrade 1.7.4 to django 1.8 south.db.mysql error, not using South