Re: PROBLEM WITH Multiple SETTINGS.PY FILE

86 views
Skip to first unread message
Message has been deleted

Jorge Gimeno

unread,
May 16, 2020, 5:20:52 PM5/16/20
to django...@googlegroups.com


On Sat, May 16, 2020 at 1:52 PM chaitan <chaitu....@gmail.com> wrote:
Hi, I am facing ModuleNotFoundError in my Django application. It got configured with multiple settings files for production, Development & Testing. 
When I Try to run Python manage.py runserver --settings= settings_dev_sai. 

This is My Settings File:

import socket

#import settings depending on the box we are on
HOST = socket.gethostname()
TPA_CODE = "Bridge"
TPA_NAME = "Bridge Benefits System"

#development
if HOST == "BITS-DP-LAPTOP":
    from settings_dev import *
    TPA_NAME = "ICBA Benefit Services Ltd."
    TPA_CODE = 'ICBA' 
#DFG bridge
elif HOST == "dfginternal":
    from settings_dfg_ees import *
    TPA_NAME = "Dehoney Financial Group"
    TPA_CODE = 'DFG' 
#test
elif HOST == "DFGTEST02":
    from settings_staging import *
elif HOST == "icbaweb":
    from settings_production_icba import *
    TPA_NAME = "ICBA Benefit Services Ltd."
    TPA_CODE = 'ICBA' 
elif HOST == "meritweb":
    from settings_production_merit import *
    TPA_NAME = "Ontario Construction Industry Benefit Plan"
    TPA_CODE = 'MERIT' 
elif HOST == "dfgweb" :
    from settings_production_dfg import *
    TPA_NAME = "Dehoney Financial Group"
    TPA_CODE = 'DFG' 
elif HOST == "dev" or HOST == "j-ubu" :
    from settings_dev_baikal import *
elif HOST == "jdev" :
    from settings_dev_juliab import *
elif HOST == "Sai" :
    from settings_dev_sai import *
elif HOST == "johnstonesweb" :
    from settings_production_johnstones import *
    TPA_NAME = "Johnstone's Benefits"
    TPA_CODE = 'JOHNSTONES' 
elif HOST == "bridgedemo" :
    from settings_demo import *
    TPA_CODE = "Bridge"
    TPA_NAME = "Bridge Benefits System"
else:
    raise ImportError("This server's hostname [" + HOST + "] does not have a proper expanded settings file. Please configure one.")
*****************

This is my settings_dev_sai

from settings_common import *

DEBUG = True
RUN_TYPE = RUN_DEV

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.postgresql_psycopg2',
        #'NAME': 'bridge_icba',
        'NAME': 'bridge_js',
        #'NAME': 'bridge_dfg_internal',
        #'NAME': 'bridge_dfg',
        'HOST': 'localhost',
        'USER': 'django',
        'PASSWORD': 'bridge_user',
        'PORT': '',
    },
}

MEDIA_ROOT = 'C:/Users/DavidPiccione/Dropbox/Work - Bridge/Projects/bridge/MEDIA/'
MEDIA_URL = '/media/'

EMAIL_HOST = 'smtp.gmail.com'
EMAIL_PORT = 587
EMAIL_HOST_USER = 'bridgeautoma...@gmail.com'
EMAIL_HOST_PASSWORD = 'bridgeautomaticmessenger123'
EMAIL_USE_TLS = True
DEFAULT_FROM_EMAIL = 'bridgeautoma...@gmail.com'


STATIC_ROOT = ''
STATIC_URL = '/static/'
STATICFILES_DIRS = ("C:/Users/DavidPiccione/Dropbox/Work - Bridge/Projects/bridge/static",)
STATIC_PATH = 'C:/Users/DavidPiccione/Dropbox/Work - Bridge/Projects/bridge/static'

TEMPLATES = [
        {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': ["C:/Users/DavidPiccione/Dropbox/Work - Bridge/Projects/bridge/TEMPLATES",],
        'APP_DIRS': False,
        'OPTIONS': {
                'context_processors': [
                'django.contrib.auth.context_processors.auth',
                'django.template.context_processors.debug',
                'django.template.context_processors.i18n',
                'django.template.context_processors.media',
                'django.template.context_processors.static',
                'django.template.context_processors.tz',
                'django.template.context_processors.request',
                'django.contrib.messages.context_processors.messages',
                'bridge.context_processors.global_settings',],
                },
        },
]


USE_ASSOCIATION_BANK_ACCOUNTS = True


******************************************************

This is settings_common file

DMINS = ()
BRIDGE_VERSION = "3.6.1 Build 202004.4" 

MANAGERS = ADMINS

TIME_ZONE = 'America/Vancouver'
LANGUAGE_CODE = 'en-us'
SITE_ID = 1

USE_I18N = True
USE_L10N = True
USE_TZ = False

# Make this unique and don't share it with anybody.
SECRET_KEY ='removed for privacy reason'
SESSION_SERIALIZER = 'django.contrib.sessions.serializers.PickleSerializer'

STATICFILES_FINDERS = (
    'django.contrib.staticfiles.finders.FileSystemFinder',
    'django.contrib.staticfiles.finders.AppDirectoriesFinder',
)

MIDDLEWARE_CLASSES = (
    'django.middleware.common.CommonMiddleware',
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.middleware.csrf.CsrfViewMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
    'bridge.request_access.Middleware',
)

ROOT_URLCONF = 'bridge.urls'
WSGI_APPLICATION = 'bridge.wsgi.application'

TEST_RUNNER = ('django.test.runner.DiscoverRunner')

INSTALLED_APPS = (
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.sites',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'django.contrib.humanize',
    'bridge',
    'block',
    'temporal',
    'log',
    'association',
    'client',
    'client_wizard',
    'employee',
    'employee_wizard',
    'receivables',
    'payables',
    'reports',
    'import_tool',
    'user_accounts',
    'carrier',
    'commission',
    # celery - async tasks.
    'django_celery_results',
    # ,'test_runner'
    'client_portal',
    #bootstrap forms for client portal
    'edi',
    'widget_tweaks', 
    'payroll_extract',
)

RQ_QUEUES = {
    'default': {
        'HOST': 'localhost',
        'PORT': 6379,
        'DB': 0,
        'DEFAULT_TIMEOUT': 360,
    },
}

LOGGING = {
    'version': 1,
    'disable_existing_loggers': False,
    'filters': {
        'require_debug_false': {
            '()': 'django.utils.log.RequireDebugFalse'
        }
    },
    'handlers': {
        'mail_admins': {
            'level': 'ERROR',
            'filters': ['require_debug_false'],
            'class': 'django.utils.log.AdminEmailHandler'
        }
    },
    'loggers': {
        'django.request': {
            'handlers': ['mail_admins'],
            'level': 'ERROR',
            'propagate': True,
        },
    }
}

# custom project settings follow...
LOGIN_URL = '/login'
LOGIN_REDIRECT_URL = '/'
AUTH_PROFILE_MODULE = "user_accounts.UserProfile"

COUNTRY_LOCALE = ''

SYSTEM_SALES_TAX = 'BC' #This is the province that the TPA client is based in. This is the fall back tax if nothing is set at the client level.
USE_ASSOCIATION_BANK_ACCOUNTS = False

ADMIN_FEE_ON_ZERO_PREMIUMS = False # overwrite by setting it to True in settings_production_BenefitAdminCompanyName.py if the Admin Fee is charged even if the current premium is zero.

# DEPRECIATED
INVOICE_ORDER = ('LIFE', 'AD&D', 'WI', 'LTD', 'DEPL', 'EHC', 'DENT', 'EAP', 'MSP', 'OPTLF', 'OSPLIF', 'OPTADD', 'OSPADD', 'VADD', 'CI',)
# END DEPRECIATED

# celery settings
CELERY_RESULT_BACKEND = 'django-db'
CELERY_IMPORTS = ("receivables.async_tasks",'edi.edi', 'payroll_extract.views')

INTERNAL_IPS = ('127.0.0.1')

'''
# RUN_TYPE is a binary flag - it can be any combination of RUN_*
# for ex. to set RUN_DEV and RUN_TEST at the same time use:

RUN_TYPE = RUN_DEV | RUN_TEST

# to check use:

if RUN_TYPE & RUN_DEV == RUN_DEV:
    #...
# or
if RUN_TYPE & RUN_DEV:
    #...

'''
RUN_DEV = 1
RUN_TEST = 2
RUN_PROD = 4
RUN_TYPE = RUN_PROD


USE_CACHE = True # enable/disable request level caching by @cache annotation
TRACK_CALLS = False # enable/disable function call count by @cache and @track annotations
TEST_CREATE_NEW_DUMP = True
TEST_RESTORE_DB = True
TEST_DB_TMPFS = False
TEST_LOG_FILE=''
TEST_USER = 'auto_test'
TEST_PSWD = 'pass'
LOG_SQL = False
USE_DEBUG_TOOLBAR = False

LEDGER_SWITCH_DATE = '2019-12-01'
***************************************************************
Error LOG


$ python manage.py makemigrations --settings=bridge.settings.settings_dev_sai
Traceback (most recent call last):
  File "C:\Users\1\AppData\Local\Programs\Python\Python38-32\lib\site-packages\django\core\management\base.py", line 328, in run_from_argv
    self.execute(*args, **cmd_options)
  File "C:\Users\1\AppData\Local\Programs\Python\Python38-32\lib\site-packages\django\core\management\base.py", line 366, in execute
    self.check()
  File "C:\Users\1\AppData\Local\Programs\Python\Python38-32\lib\site-packages\django\core\management\base.py", line 392, in check
    all_issues = self._run_checks(
  File "C:\Users\1\AppData\Local\Programs\Python\Python38-32\lib\site-packages\django\core\management\base.py", line 382, in _run_checks
    return checks.run_checks(**kwargs)
  File "C:\Users\1\AppData\Local\Programs\Python\Python38-32\lib\site-packages\django\core\checks\registry.py", line 72, in run_checks
    new_errors = check(app_configs=app_configs)
  File "C:\Users\1\AppData\Local\Programs\Python\Python38-32\lib\site-packages\django\core\checks\translation.py", line 32, in check_setting_language_code
    tag = settings.LANGUAGE_CODE
  File "C:\Users\1\AppData\Local\Programs\Python\Python38-32\lib\site-packages\django\conf\__init__.py", line 76, in __getattr__
    self._setup(name)
  File "C:\Users\1\AppData\Local\Programs\Python\Python38-32\lib\site-packages\django\conf\__init__.py", line 63, in _setup
    self._wrapped = Settings(settings_module)
  File "C:\Users\1\AppData\Local\Programs\Python\Python38-32\lib\site-packages\django\conf\__init__.py", line 142, in __init__
    mod = importlib.import_module(self.SETTINGS_MODULE)
  File "C:\Users\1\AppData\Local\Programs\Python\Python38-32\lib\importlib\__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
  File "<frozen importlib._bootstrap>", line 991, in _find_and_load
  File "<frozen importlib._bootstrap>", line 961, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
  File "<frozen importlib._bootstrap>", line 991, in _find_and_load
  File "<frozen importlib._bootstrap>", line 975, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 671, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 783, in exec_module
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "F:\brdge\bridge_sai\bridge\settings.py", line 38, in <module>
    from settings_dev_sai import *
ModuleNotFoundError: No module named 'settings_dev_sai'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "manage.py", line 10, in <module>
    execute_from_command_line(sys.argv)
  File "C:\Users\1\AppData\Local\Programs\Python\Python38-32\lib\site-packages\django\core\management\__init__.py", line 401, in execute_from_command_line
    utility.execute()
  File "C:\Users\1\AppData\Local\Programs\Python\Python38-32\lib\site-packages\django\core\management\__init__.py", line 395, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "C:\Users\1\AppData\Local\Programs\Python\Python38-32\lib\site-packages\django\core\management\base.py", line 341, in run_from_argv
    connections.close_all()
  File "C:\Users\1\AppData\Local\Programs\Python\Python38-32\lib\site-packages\django\db\utils.py", line 225, in close_all
    for alias in self:
  File "C:\Users\1\AppData\Local\Programs\Python\Python38-32\lib\site-packages\django\db\utils.py", line 219, in __iter__
    return iter(self.databases)
  File "C:\Users\1\AppData\Local\Programs\Python\Python38-32\lib\site-packages\django\utils\functional.py", line 48, in __get__
    res = instance.__dict__[self.name] = self.func(instance)
  File "C:\Users\1\AppData\Local\Programs\Python\Python38-32\lib\site-packages\django\db\utils.py", line 153, in databases
    self._databases = settings.DATABASES
  File "C:\Users\1\AppData\Local\Programs\Python\Python38-32\lib\site-packages\django\conf\__init__.py", line 76, in __getattr__
    self._setup(name)
  File "C:\Users\1\AppData\Local\Programs\Python\Python38-32\lib\site-packages\django\conf\__init__.py", line 63, in _setup
    self._wrapped = Settings(settings_module)
  File "C:\Users\1\AppData\Local\Programs\Python\Python38-32\lib\site-packages\django\conf\__init__.py", line 142, in __init__
    mod = importlib.import_module(self.SETTINGS_MODULE)
  File "C:\Users\1\AppData\Local\Programs\Python\Python38-32\lib\importlib\__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
  File "<frozen importlib._bootstrap>", line 991, in _find_and_load
  File "<frozen importlib._bootstrap>", line 961, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
  File "<frozen importlib._bootstrap>", line 991, in _find_and_load
  File "<frozen importlib._bootstrap>", line 975, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 671, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 783, in exec_module
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "F:\brdge\bridge_sai\bridge\settings.py", line 38, in <module>
    from settings_dev_sai import *
ModuleNotFoundError: No module named 'settings_dev_sai'

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/aaf003fe-55f1-4b2c-9369-be9a1ee6f79d%40googlegroups.com.

Are your settings file in their own folder?

-Jorge
Message has been deleted
Message has been deleted

Jorge Gimeno

unread,
May 16, 2020, 7:55:19 PM5/16/20
to django...@googlegroups.com
It's coming from your settings file.  I would try this:

In this line here:
elif HOST == "Sai" :
    from settings_dev_sai import *

I would try to make the second line:
    from .settings_dev_sai import *

See if Python can find the module that way.  If Python does, then all of the imports in that file need to be changed.

If that's not the case, then we need to see what the directory structure looks like to figure this out.

-Jorge

On Sat, May 16, 2020 at 4:04 PM chaitanya orakala <chaitu....@gmail.com> wrote:
Do you have any idea why i am getting this error? 

On Sat, May 16, 2020 at 6:40 PM chaitanya orakala <chaitu....@gmail.com> wrote:
Yes Jorge, all the settings file are in the same folder


--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
Message has been deleted

chaitanya orakala

unread,
May 18, 2020, 9:12:12 PM5/18/20
to django...@googlegroups.com
hey could anyone help with this? 

On Mon, May 18, 2020 at 2:44 PM chaitanya orakala <chaitu....@gmail.com> wrote:
Hi Jorge,
I tried placing a dot in front of settings_dev_sai, it didn't work. by the way, I am using Python 2.7 and Django 1.10 versions.
image.png
this is my project structure.  I am using a virtual environment.
Please let me know what you think sir

Mike Dewhirst

unread,
May 18, 2020, 9:30:21 PM5/18/20
to django...@googlegroups.com
On 19/05/2020 11:10 am, chaitanya orakala wrote:
> I am using Python 2.7

It is possible you need a top line in the file like this ...

from __future__ import absolute_import

I haven't been following this thread so someone may have mentioned that
already.


Message has been deleted

Jorge Gimeno

unread,
May 19, 2020, 2:45:26 PM5/19/20
to django...@googlegroups.com
I'm not sure why you're getting an exception.  I know the import mechanism in Python 2 was a bit different, so I'm not sure if that's the issue or if Django's import mechanism isn't finding your settings file.

I don't know if you have tried this, but I saw a blog post on using multiple settings files.  Maybe it will help:  https://simpleisbetterthancomplex.com/tips/2017/07/03/django-tip-20-working-with-multiple-settings-modules.html

I hope this helps!

-Jorge

On Mon, May 18, 2020 at 6:51 PM chaitanya orakala <chaitu....@gmail.com> wrote:
I tried that way, sir. but it's of no use. I don't know how to resolve this issue. its been troubling me for 3 days now

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
Message has been deleted

Mike Dewhirst

unread,
May 19, 2020, 9:08:39 PM5/19/20
to django...@googlegroups.com
I thought I'd go back and look at your original post. Your settings file
looks a bit tricky.

I learned to deal with multiple settings files a long time ago so I
don't know what current best practice is. Essentially, the way I do it
is to have a complete base.py with all settings in a default state for
security and production components. Then I have all my separate settings
files ...

from base import *

... followed by the adjusted settings for that environment. Typically
they will be production.py, staging.py and local.py

Then depending on the environment my wsgi.py imports settings.production
or settings.mike-local or whatever.

It looks to me as though you are doing the opposite. Your wsgi.py
imports a single settings file which has a massive if/elif block to
import one of a multitude of other settings files each of which imports
the equivalent of my base.py (your settings_common.py)

My mechanism has a single import statement while yours has at least two.

I think your wsgi.py should have the massive if/elif block to simply
name the correct settings file (based on the host name) whenever the web
server reloads.

It might reduce importing complexity somewhat and possibly solve the
problem.

My settings arrangement is

base - all the settings as defaults
production - all the production settings no matter which host
staging - all the staging settings no matter which host
local - all the local settings including detecting the OS, setting DEBUG
switching off security etc
local-mike - all my own settings including sqlite for faster testing
local-test - including postgreSQL for rigorous testing

I also needed to simulate environments. My mechanism is to rename the
project directory and detect that in my settings.base.py like this ...

if deploy_dir == 'bis':     # pragma: no cover
    PRODUCTION = "pq3"    # hostname
    DOMAIN = 'djfghdsgdlg.com'
    BRANDING = 'BIS'
    BRAND_URL = 'https://www.{0}/'.format(DOMAIN)
    ADMIN_URL = 'https://pay.{0}/admin'.format(DOMAIN)
    ALLOWED_HOSTS = [u'pay.{0}'.format(DOMAIN)]
    FUNCTION = 'invoice'
elif deploy_dir == 'cli':     # pragma: no cover
    etc etc

I also wrote a couple of utilities which are called from dev versions of
my settings files. They print out all settings which significantly
change between hosts depending on which host I'm simulating.

In summary, I don't think I can help just by looking at the error -
other than the obvious error being reported in a settings file - but I
would definitely try and simplify the importing. And I do like to print
out all the essential settings every time runserver reloads.

Good luck

M



On 20/05/2020 9:59 am, chaitanya orakala wrote:
> Thank Jeorge. I went through that blog long back but I can't find a
> relation to my Error. I will try contacting my manager regarding this.
> will let you know if I find anything. Have a great day
> <mailto:django-users%2Bunsu...@googlegroups.com>.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/95afb956-98f8-6664-9107-d0935b75cf6c%40dewhirst.com.au.
>
> --
> You received this message because you are subscribed to the
> Google Groups "Django users" group.
> To unsubscribe from this group and stop receiving emails from
> it, send an email to django-users...@googlegroups.com
> <mailto:django-users...@googlegroups.com>.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/CAPcTzRZHgBG1Q90Rk8VmNS%2ByzmQLd1bdq8ZPgA6A%2Bumsx4CGvw%40mail.gmail.com
> <https://groups.google.com/d/msgid/django-users/CAPcTzRZHgBG1Q90Rk8VmNS%2ByzmQLd1bdq8ZPgA6A%2Bumsx4CGvw%40mail.gmail.com?utm_medium=email&utm_source=footer>.
>
> --
> You received this message because you are subscribed to the Google
> Groups "Django users" group.
> To unsubscribe from this group and stop receiving emails from it,
> send an email to django-users...@googlegroups.com
> <mailto:django-users...@googlegroups.com>.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/CANfN%3DK9MAMn3WezyhMU5Rrv5DWWFNxQ0jc9RnfyK-qyCOiV%2BeA%40mail.gmail.com
> <https://groups.google.com/d/msgid/django-users/CANfN%3DK9MAMn3WezyhMU5Rrv5DWWFNxQ0jc9RnfyK-qyCOiV%2BeA%40mail.gmail.com?utm_medium=email&utm_source=footer>.
>
> --
> You received this message because you are subscribed to the Google
> Groups "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to django-users...@googlegroups.com
> <mailto:django-users...@googlegroups.com>.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/CAPcTzRaZCKqFZ-smQwNscYtmivyt1_tHhvF94wyN60LVHu4Wvw%40mail.gmail.com
> <https://groups.google.com/d/msgid/django-users/CAPcTzRaZCKqFZ-smQwNscYtmivyt1_tHhvF94wyN60LVHu4Wvw%40mail.gmail.com?utm_medium=email&utm_source=footer>.

Hella Nick

unread,
May 19, 2020, 10:46:09 PM5/19/20
to Django users
你帮我获得加拿大的工作移民签证,我就可以帮你解决问题。

在 2020年5月17日星期日 UTC+8上午4:51:45,chaitan写道:
Reply all
Reply to author
Forward
0 new messages