我们从Python开源项目中,提取了以下8个代码示例,用于说明如何使用django.conf.Settings()。
def test_settings(self): from django import conf settings_mod = sys.modules[self.mod_name] settings_mod.DEBUG = True settings_mod.AMF_TIME_OFFSET = 1000 old_settings = conf.settings conf.settings = conf.Settings(self.mod_name) gw = django.DjangoGateway() try: self.assertTrue(gw.debug) self.assertEqual(gw.timezone_offset, 1000) finally: conf.settings = old_settings
def handle(self, **options): # Inspired by Postfix's "postconf -n". from django.conf import settings, Settings, global_settings # Because settings are imported lazily, we need to explicitly load them. settings._setup() user_settings = module_to_dict(settings._wrapped) default = options['default'] default_settings = module_to_dict(Settings(default) if default else global_settings) output = [] for key in sorted(user_settings): if key not in default_settings: output.append("%s = %s ###" % (key, user_settings[key])) elif user_settings[key] != default_settings[key]: output.append("%s = %s" % (key, user_settings[key])) elif options['all']: output.append("### %s = %s" % (key, user_settings[key])) return '\n'.join(output)
def set_isolated(self, value): if value: self._isolated_overrides = BaseSettings() self._isolated = value
def revert(self): """ Revert any changes made to settings. """ for attr, value in self._changed.items(): setattr(django_settings, attr, value) for attr in self._added: delattr(django_settings, attr) self._changed = {} self._added = [] if self.isolated: self._isolated_overrides = BaseSettings()