Django: ImproperlyConfigured: The SECRET_KEY setting must not be empty

I am trying to set up multiple setting files (development, production, ..) that include some base settings. Cannot succeed though. When I try to run ./ runserver I am getting the following error:

    (cb)clime@den /srv/www/cb $ ./ runserver
    ImproperlyConfigured: The SECRET_KEY setting must not be empty.

Here is my settings module:

    (cb)clime@den /srv/www/cb/cb/settings $ ll
    total 24
    -rw-rw-r--. 1 clime clime 8230 Oct  2 02:56
    -rw-rw-r--. 1 clime clime  489 Oct  2 03:09
    -rw-rw-r--. 1 clime clime   24 Oct  2 02:34
    -rw-rw-r--. 1 clime clime  471 Oct  2 02:51

Base settings (contain SECRET_KEY):

    (cb)clime@den /srv/www/cb/cb/settings $ cat
    # Django base settings for cb project.

    import django.conf.global_settings as defaults

    DEBUG = False

    INTERNAL_IPS = ('',)

    ADMINS = (
        ('clime', '[email protected]'),


        'default': {
            #'ENGINE': 'django.db.backends.postgresql_psycopg2', # Add 'postgresql_psycopg2', 'mysql', 'sqlite3' or 'oracle'.
            'ENGINE': 'django.db.backends.postgresql_psycopg2',
            'NAME': 'cwu',                   # Or path to database file if using sqlite3.
            'USER': 'clime',                 # Not used with sqlite3.
            'PASSWORD': '',                  # Not used with sqlite3.
            'HOST': '',                      # Set to empty string for localhost. Not used with sqlite3.
            'PORT': '',                      # Set to empty string for default. Not used with sqlite3.

    # Local time zone for this installation. Choices can be found here:
    # although not all choices may be available on all operating systems.
    # In a Windows environment this must be set to your system time zone.
    TIME_ZONE = 'Europe/Prague'

    # Language code for this installation. All choices can be found here:
    LANGUAGE_CODE = 'en-us'

    SITE_ID = 1

    # If you set this to False, Django will make some optimizations so as not
    # to load the internationalization machinery.
    USE_I18N = False

    # If you set this to False, Django will not format dates, numbers and
    # calendars according to the current locale.
    USE_L10N = False # TODO: make this true and accustom date time input

    DATE_INPUT_FORMATS = defaults.DATE_INPUT_FORMATS + ('%d %b %y', '%d %b, %y') # + ('25 Oct 13', '25 Oct, 13')

    # If you set this to False, Django will not use timezone-aware datetimes.
    USE_TZ = True

    # Absolute filesystem path to the directory that will hold user-uploaded files.
    # Example: "/home/media/"
    MEDIA_ROOT = '/srv/www/cb/media'

    # URL that handles the media served from MEDIA_ROOT. Make sure to use a
    # trailing slash.
    # Examples: "", ""
    MEDIA_URL = '/media/'

    # Absolute path to the directory static files should be collected to.
    # Don't put anything in this directory yourself; store your static files
    # in apps' "static/" subdirectories and in STATICFILES_DIRS.
    # Example: "/home/media/"
    STATIC_ROOT = '/srv/www/cb/static'

    # URL prefix for static files.
    # Example: ""
    STATIC_URL = '/static/'

    # Additional locations of static files
        # Put strings here, like "/home/html/static" or "C:/www/django/static".
        # Always use forward slashes, even on Windows.
        # Don't forget to use absolute paths, not relative paths.

    # List of finder classes that know how to find static files in
    # various locations.
    #    'django.contrib.staticfiles.finders.DefaultStorageFinder',

    # Make this unique, and don't share it with anybody.
    SECRET_KEY = '8lu*6g0lg)9z!ba+a$ehk)xt)x%rxgb$i1&022shmi1jcgihb*'

    # List of callables that know how to import templates from various sources.
    #     'django.template.loaders.eggs.Loader',


        # Uncomment the next line for simple clickjacking protection:
        # 'django.middleware.clickjacking.XFrameOptionsMiddleware',

    ROOT_URLCONF = 'cb.urls'

    # Python dotted path to the WSGI application used by Django's runserver.
    WSGI_APPLICATION = 'cb.wsgi.application'

        # Put strings here, like "/home/html/django_templates" or "C:/www/django/templates".
        # Always use forward slashes, even on Windows.
        # Don't forget to use absolute paths, not relative paths.

        'grappelli', # must be before admin

    AUTH_USER_MODEL = 'web.User'

    # A sample logging configuration. The only tangible logging
    # performed by this configuration is to send an email to
    # the site admins on every HTTP 500 error when DEBUG=False.
    # See for
    # more details on how to customize your logging configuration.
    LOGGING = {
        'version': 1,
        'disable_existing_loggers': False,
        'filters': {
            'require_debug_false': {
                '()': 'django.utils.log.RequireDebugFalse'
        'formatters': {
            'standard': {
                'format' : "[%(asctime)s] %(levelname)s [%(name)s:%(lineno)s] %(message)s",
                'datefmt' : "%d/%b/%Y %H:%M:%S"
        'handlers': {
            'mail_admins': {
                'level': 'ERROR',
                'filters': ['require_debug_false'],
                'class': 'django.utils.log.AdminEmailHandler'
            'null': {
            'logfile': {
                'filename': "/srv/www/cb/logs/application.log",
                'maxBytes': 50000,
                'backupCount': 2,
                'formatter': 'standard',
                'formatter': 'standard'
        'loggers': {
            'django.request': {
                'handlers': ['mail_admins'],
                'level': 'ERROR',
                'propagate': True,
            'django': {
                'propagate': True,
            'django.db.backends': {
                'handlers': ['console'],
                'level': 'DEBUG',
                'propagate': False,
            'web': {
                'handlers': ['console', 'logfile'],
                'level': 'DEBUG',

    LOGIN_URL = 'login'
    LOGOUT_URL = 'logout'

    #    <img src="/static/web/img/preloader.gif" alt="loading" style="margin:auto"/>
        <div class="spinner small" style="margin:auto">
            <div class="block_1 spinner_block small"></div>
            <div class="block_2 spinner_block small"></div>
            <div class="block_3 spinner_block small"></div>


    import django.template.loader

    WATSON_POSTGRESQL_SEARCH_CONFIG = 'public.english_nostop'

One of the setting files:

    (cb)clime@den /srv/www/cb/cb/settings $ cat 
    from base import *

    DEBUG = True

    ALLOWED_HOSTS = ['', '']

        'default': {
            'ENGINE': 'django.db.backends.postgresql_psycopg2',
            'NAME': 'cwu',
            'USER': 'clime',
            'PASSWORD': '',
            'HOST': '',
            'PORT': '',

    MEDIA_ROOT = '/srv/www/cb/media/'

    STATIC_ROOT = '/srv/www/cb/static/'


Code in

    (cb)clime@den /srv/www/cb $ cat 
    #!/usr/bin/env python
    import os
    import sys

    if __name__ == "__main__":
        os.environ.setdefault("DJANGO_SETTINGS_MODULE", "cb.settings.development")

        from import execute_from_command_line


If I add from base import * into /srv/www/cb/cb/settings/ (which is otherwise empty), it magically starts to work but I don't understand why. Anyone could explain to me what's going on here? It must be some python module magic.

EDIT: Everything also starts to work if I remove this line from


If I remove this line from web.templatetags.cb_tags, it also starts to work:

    from endless_pagination.templatetags import endless

I guess it is because, in the end, it leads to

    from django.conf import settings
    PER_PAGE = getattr(settings, 'ENDLESS_PAGINATION_PER_PAGE', 10)

So it creates some weird circular stuff and game over.

I had the same error and it turned out to be a circular dependency between something loaded by the settings and the settings module itself. In my case it was a middleware class which was named in the settings which itself tried to load the settings.


Back to homepage or read more recommendations: