2013-05-08 55 views
0

我有一个settings.py文件,它包含基本设置。然后我有一个local_settings.py文件,其中包含一些分析和测试应用程序,如django_debug_toolbar等,然后我有一个不同的production_settings.py文件,其中包含数据库设置等生产。django不同的production_settings文件

我已将local_settings.py文件添加到我的.gitignore,以便它不会被推送到生产。而在我的settings.py文件,我已经把下列 -

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 

我在Heroku上运行的东西。问题在于production_settings中的设置没有反映在生产服务器上,出了什么问题? 请帮忙,谢谢!

回答

0

在生产服务器local_settings不存在,因此导入将失败。但是当你试图从production_settings导入时,你只是忽略了引发异常的情况。从production_settings导入时请勿使用tryexcept。我想知道是否有一些例外被提出,这就是为什么这些变化没有被反映出来。例如,我想到的一个例外是,可能是INSTALLED_APPSsettings.py中的元组,但PROD_APPS是列表(反之亦然),因此元组与列表的连接将引起TypeError

更好的办法:

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