本文整理匯總了Python中django.conf.settings._setup方法的典型用法代碼示例。如果您正苦於以下問題:Python settings._setup方法的具體用法?Python settings._setup怎麽用?Python settings._setup使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類django.conf.settings
的用法示例。
在下文中一共展示了settings._setup方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: handle
# 需要導入模塊: from django.conf import settings [as 別名]
# 或者: from django.conf.settings import _setup [as 別名]
def handle(self, **options):
# Inspired by Postfix's "postconf -n".
from django.conf import settings, global_settings
# Because settings are imported lazily, we need to explicitly load them.
settings._setup()
user_settings = module_to_dict(settings._wrapped)
default_settings = module_to_dict(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)
示例2: handle_noargs
# 需要導入模塊: from django.conf import settings [as 別名]
# 或者: from django.conf.settings import _setup [as 別名]
def handle_noargs(self, **options):
# Inspired by Postfix's "postconf -n".
from django.conf import settings, global_settings
# Because settings are imported lazily, we need to explicitly load them.
settings._setup()
user_settings = module_to_dict(settings._wrapped)
default_settings = module_to_dict(global_settings)
output = []
for key in sorted(user_settings.keys()):
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]))
return '\n'.join(output)
示例3: django_setup
# 需要導入模塊: from django.conf import settings [as 別名]
# 或者: from django.conf.settings import _setup [as 別名]
def django_setup(settings_module=None):
"""Initialize Django if required, must be run before performing
any task on spooler or mule.
"""
from django.conf import settings, ENVIRONMENT_VARIABLE
if settings.configured:
return
if settings_module:
import os
os.environ[ENVIRONMENT_VARIABLE] = settings_module
try:
# django > 1.7
from django import setup
except ImportError:
# django < 1.7
def setup():
settings._setup()
setup()
示例4: setup_django_settings
# 需要導入模塊: from django.conf import settings [as 別名]
# 或者: from django.conf.settings import _setup [as 別名]
def setup_django_settings(test_settings):
"""Override the enviroment variable and call the _setup method of the settings object to reload them."""
os.environ['DJANGO_SETTINGS_MODULE'] = test_settings
from django.conf import settings as django_settings
# (re)setup django settings
django_settings._setup()
# reload settings
reload_settings(django_settings)
示例5: test_no_settings_module
# 需要導入模塊: from django.conf import settings [as 別名]
# 或者: from django.conf.settings import _setup [as 別名]
def test_no_settings_module(self):
msg = (
'Requested setting%s, but settings are not configured. You '
'must either define the environment variable DJANGO_SETTINGS_MODULE '
'or call settings.configure() before accessing settings.'
)
orig_settings = os.environ[ENVIRONMENT_VARIABLE]
os.environ[ENVIRONMENT_VARIABLE] = ''
try:
with self.assertRaisesMessage(ImproperlyConfigured, msg % 's'):
settings._setup()
with self.assertRaisesMessage(ImproperlyConfigured, msg % ' TEST'):
settings._setup('TEST')
finally:
os.environ[ENVIRONMENT_VARIABLE] = orig_settings
示例6: test_incorrect_timezone
# 需要導入模塊: from django.conf import settings [as 別名]
# 或者: from django.conf.settings import _setup [as 別名]
def test_incorrect_timezone(self):
with self.assertRaisesMessage(ValueError, 'Incorrect timezone setting: test'):
settings._setup()
示例7: initialize_django
# 需要導入模塊: from django.conf import settings [as 別名]
# 或者: from django.conf.settings import _setup [as 別名]
def initialize_django(settings_module: str) -> Tuple['Apps', 'LazySettings']:
with temp_environ():
os.environ['DJANGO_SETTINGS_MODULE'] = settings_module
# add current directory to sys.path
sys.path.append(os.getcwd())
def noop_class_getitem(cls, key):
return cls
from django.db import models
models.QuerySet.__class_getitem__ = classmethod(noop_class_getitem) # type: ignore
models.Manager.__class_getitem__ = classmethod(noop_class_getitem) # type: ignore
from django.conf import settings
from django.apps import apps
apps.get_models.cache_clear() # type: ignore
apps.get_swappable_settings_name.cache_clear() # type: ignore
if not settings.configured:
settings._setup()
apps.populate(settings.INSTALLED_APPS)
assert apps.apps_ready
assert settings.configured
return apps, settings