Question

I have a settings.py file, that contains basic settings. Then I have a local_settings.py file, that contains some profiling and testing apps as django_debug_toolbar etc. and then I have a different production_settings.py file, that contains db settings etc. for the production.

I have added local_settings.py file to my .gitignore so that it does not get pushed to the production. And in my settings.py file, I have put the following -

try:
    from local_settings import *
    INSTALLED_APPS += LS_APPS
    MIDDLEWARE_CLASSES += LS_MIDDLEWARE_CLASSES
except ImportError:
    try:
        from production_settings import *
        INSTALLED_APPS += PROD_APPS
    except:
        pass

I am running things on heroku. The trouble is that the settings in production_settings are not being reflected on the production server, what is wrong? Please help, thanks!

Was it helpful?

Solution

In production server local_settings does not exists so the import will failed. But when you are trying to import from production_settings you are just ignoring the exception if it is raised. Do not use try and except while importing from production_settings. I wonder if there is some exception is raised and that is why those changes are not being reflected. For example one exception which i thought of is that may be INSTALLED_APPS is a tuple in settings.py but PROD_APPS is a list (or vice versa) so concatination of tuple with list will raise TypeError.

Better way:

try:
    from local_settings import *
    INSTALLED_APPS += LS_APPS
    MIDDLEWARE_CLASSES += LS_MIDDLEWARE_CLASSES
except ImportError:
    from production_settings import *
    INSTALLED_APPS += PROD_APPS
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top