title: Django ImproperlyConfigured - The SECRET_KEY setting must not be empty
body: <p>I am running a django application using celery. I am getting a strange error in my <em>tasks.py</em> file, which is as follows:</p>
  
  <pre><code>from __future__ import absolute_import
  
  from celery import shared_task
  from django.contrib.auth.models import User
  
  # some code 
  # ....
  </code></pre>
  
  <p>Here is the error:</p>
  
  <pre><code>django.core.exceptions.ImproperlyConfigured: The SECRET_KEY must not be empty.
  </code></pre>
  
  <p>In my <em>settings.py</em>, SECRET_KEY <strong>is defined</strong></p>
  
  <pre><code># ...
  import myproj.tasks
  import djcelery
  
  djcelery.setup_loader()
  
  # ...
  SECRET_KEY = '18730s9n9sjxamsuJSismxOIAmso102xjAs'
  # ...
  </code></pre>
  
  <p>The application <strong>runs fine if I comment the import</strong> in the <em>tasks.py</em> file:</p>
  
  <pre><code># from django.contrib.auth.models import User
  </code></pre>
  
  <p>and, more surprisingly, it also runs fine if I make the <strong>exact same imports</strong> in another file (e.g. testfile.py) in the same directory.</p>
  
  <p>Why is this error happening?</p>
  
  <p><strong>Edit:</strong> Here is my <em>celery.py</em> file</p>
  
  <pre><code>from __future__ import absolute_import
  import os
  from celery import Celery
  
  os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'myproj.settings')
  
  from django.conf import settings #noqa
  
  app = Celery('myproj')
  
  app.config_from_object('django.conf:settings')
  app.autodiscover_tasks(lambda: settings.INSTALLED_APPS)
  </code></pre>