本文整理汇总了Python中django.conf.settings.configured方法的典型用法代码示例。如果您正苦于以下问题:Python settings.configured方法的具体用法?Python settings.configured怎么用?Python settings.configured使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类django.conf.settings
的用法示例。
在下文中一共展示了settings.configured方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: runtests
# 需要导入模块: from django.conf import settings [as 别名]
# 或者: from django.conf.settings import configured [as 别名]
def runtests(*test_args):
if not settings.configured:
settings.configure(**DEFAULT_SETTINGS)
# Compatibility with Django 1.7's stricter initialization
if hasattr(django, "setup"):
django.setup()
parent = os.path.dirname(os.path.abspath(__file__))
sys.path.insert(0, parent)
try:
from django.test.runner import DiscoverRunner
runner_class = DiscoverRunner
test_args = ["pinax.documents.tests"]
except ImportError:
from django.test.simple import DjangoTestSuiteRunner
runner_class = DjangoTestSuiteRunner
test_args = ["tests"]
failures = runner_class(verbosity=1, interactive=True, failfast=False).run_tests(test_args)
sys.exit(failures)
示例2: setup_django
# 需要导入模块: from django.conf import settings [as 别名]
# 或者: from django.conf.settings import configured [as 别名]
def setup_django():
import django
from django.conf import settings
if not settings.configured:
settings.configure(
DEBUG=True,
DATABASES={
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': ':memory:',
}
},
INSTALLED_APPS=(
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django_ftpserver',
)
)
django.setup()
from django.apps import apps
if not apps.ready:
apps.populate()
示例3: runtests
# 需要导入模块: from django.conf import settings [as 别名]
# 或者: from django.conf.settings import configured [as 别名]
def runtests(*test_args):
if not settings.configured:
settings.configure(**DEFAULT_SETTINGS)
django.setup()
parent = os.path.dirname(os.path.abspath(__file__))
sys.path.insert(0, parent)
try:
from django.test.runner import DiscoverRunner
runner_class = DiscoverRunner
if not test_args:
test_args = ["pinax.forums.tests"]
except ImportError:
from django.test.simple import DjangoTestSuiteRunner
runner_class = DjangoTestSuiteRunner
test_args = ["tests"]
failures = runner_class(verbosity=1, interactive=True, failfast=False).run_tests(test_args)
sys.exit(failures)
示例4: runtests
# 需要导入模块: from django.conf import settings [as 别名]
# 或者: from django.conf.settings import configured [as 别名]
def runtests():
if not settings.configured:
settings.configure(**DEFAULT_SETTINGS)
django.setup()
from spillway.models import upload_to
os.mkdir(os.path.join(TMPDIR, upload_to.path))
parent = os.path.dirname(os.path.abspath(__file__))
sys.path.insert(0, parent)
try:
from django.test.runner import DiscoverRunner
runner_class = DiscoverRunner
except ImportError:
from django.test.simple import DjangoTestSuiteRunner
runner_class = DjangoTestSuiteRunner
try:
status = runner_class(
verbosity=1, interactive=True, failfast=False).run_tests(['tests'])
except Exception:
traceback.print_exc()
status = 1
finally:
teardown()
sys.exit(status)
示例5: read_template_source
# 需要导入模块: from django.conf import settings [as 别名]
# 或者: from django.conf.settings import configured [as 别名]
def read_template_source(filename):
"""Read the source of a Django template, returning the Unicode text."""
# Import this late to be sure we don't trigger settings machinery too
# early.
from django.conf import settings
if not settings.configured:
settings.configure()
with open(filename, "rb") as f:
# The FILE_CHARSET setting will be removed in 3.1:
# https://docs.djangoproject.com/en/3.0/ref/settings/#file-charset
if django.VERSION >= (3, 1):
charset = 'utf-8'
else:
charset = settings.FILE_CHARSET
text = f.read().decode(charset)
return text
示例6: runtests
# 需要导入模块: from django.conf import settings [as 别名]
# 或者: from django.conf.settings import configured [as 别名]
def runtests(*test_args):
if not settings.configured:
settings.configure(**DEFAULT_SETTINGS)
django.setup()
parent = os.path.dirname(os.path.abspath(__file__))
sys.path.insert(0, parent)
try:
from django.test.runner import DiscoverRunner
runner_class = DiscoverRunner
test_args = ["pinax.teams.tests"]
except ImportError:
from django.test.simple import DjangoTestSuiteRunner
runner_class = DjangoTestSuiteRunner
test_args = ["tests"]
failures = runner_class(
verbosity=1, interactive=True, failfast=False).run_tests(test_args)
sys.exit(failures)
示例7: runtests
# 需要导入模块: from django.conf import settings [as 别名]
# 或者: from django.conf.settings import configured [as 别名]
def runtests(*test_args):
if not settings.configured:
settings.configure(**DEFAULT_SETTINGS)
django.setup()
parent = os.path.dirname(os.path.abspath(__file__))
sys.path.insert(0, parent)
try:
from django.test.runner import DiscoverRunner
runner_class = DiscoverRunner
if not test_args:
test_args = ["pinax.wiki.tests"]
except ImportError:
from django.test.simple import DjangoTestSuiteRunner
runner_class = DjangoTestSuiteRunner
test_args = ["tests"]
failures = runner_class(verbosity=1, interactive=True, failfast=False).run_tests(test_args)
sys.exit(failures)
示例8: django_setup
# 需要导入模块: from django.conf import settings [as 别名]
# 或者: from django.conf.settings import configured [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()
示例9: runtests
# 需要导入模块: from django.conf import settings [as 别名]
# 或者: from django.conf.settings import configured [as 别名]
def runtests(*test_args):
if not settings.configured:
settings.configure(**DEFAULT_SETTINGS)
django.setup()
parent = os.path.dirname(os.path.abspath(__file__))
sys.path.insert(0, parent)
try:
from django.test.runner import DiscoverRunner
runner_class = DiscoverRunner
if not test_args:
test_args = ["borme.tests"]
except ImportError:
from django.test.simple import DjangoTestSuiteRunner
runner_class = DjangoTestSuiteRunner
if not test_args:
test_args = ["tests"]
failures = runner_class(verbosity=1,
interactive=True,
failfast=False).run_tests(test_args)
sys.exit(failures)
示例10: run
# 需要导入模块: from django.conf import settings [as 别名]
# 或者: from django.conf.settings import configured [as 别名]
def run(*args):
if not settings.configured:
settings.configure(**DEFAULT_SETTINGS)
django.setup()
parent = os.path.dirname(os.path.abspath(__file__))
sys.path.insert(0, parent)
django.core.management.call_command(
"makemigrations",
"documents",
*args
)
示例11: run
# 需要导入模块: from django.conf import settings [as 别名]
# 或者: from django.conf.settings import configured [as 别名]
def run():
if not settings.configured:
raise ImproperlyConfigured("You should call configure() after configuration define.")
if _parent_module.__name__ == '__main__':
from django.core.management import execute_from_command_line
execute_from_command_line(sys.argv)
else:
from django.core.wsgi import get_wsgi_application
return get_wsgi_application()
示例12: get_commands
# 需要导入模块: from django.conf import settings [as 别名]
# 或者: from django.conf.settings import configured [as 别名]
def get_commands():
"""
Returns a dictionary mapping command names to their callback applications.
This works by looking for a management.commands package in django.core, and
in each installed application -- if a commands package exists, all commands
in that package are registered.
Core commands are always included. If a settings module has been
specified, user-defined commands will also be included.
The dictionary is in the format {command_name: app_name}. Key-value
pairs from this dictionary can then be used in calls to
load_command_class(app_name, command_name)
If a specific version of a command must be loaded (e.g., with the
startapp command), the instantiated module can be placed in the
dictionary in place of the application name.
The dictionary is cached on the first call and reused on subsequent
calls.
"""
commands = {name: 'django.core' for name in find_commands(upath(__path__[0]))}
if not settings.configured:
return commands
for app_config in reversed(list(apps.get_app_configs())):
path = os.path.join(app_config.path, 'management')
commands.update({name: app_config.name for name in find_commands(path)})
return commands
示例13: main_help_text
# 需要导入模块: from django.conf import settings [as 别名]
# 或者: from django.conf.settings import configured [as 别名]
def main_help_text(self, commands_only=False):
"""
Returns the script's main help text, as a string.
"""
if commands_only:
usage = sorted(get_commands().keys())
else:
usage = [
"",
"Type '%s help <subcommand>' for help on a specific subcommand." % self.prog_name,
"",
"Available subcommands:",
]
commands_dict = collections.defaultdict(lambda: [])
for name, app in six.iteritems(get_commands()):
if app == 'django.core':
app = 'django'
else:
app = app.rpartition('.')[-1]
commands_dict[app].append(name)
style = color_style()
for app in sorted(commands_dict.keys()):
usage.append("")
usage.append(style.NOTICE("[%s]" % app))
for name in sorted(commands_dict[app]):
usage.append(" %s" % name)
# Output an extra note if settings are not properly configured
if self.settings_exception is not None:
usage.append(style.NOTICE(
"Note that only Django core commands are listed "
"as settings are not properly configured (error: %s)."
% self.settings_exception))
return '\n'.join(usage)
示例14: get_commands
# 需要导入模块: from django.conf import settings [as 别名]
# 或者: from django.conf.settings import configured [as 别名]
def get_commands():
"""
Return a dictionary mapping command names to their callback applications.
Look for a management.commands package in django.core, and in each
installed application -- if a commands package exists, register all
commands in that package.
Core commands are always included. If a settings module has been
specified, also include user-defined commands.
The dictionary is in the format {command_name: app_name}. Key-value
pairs from this dictionary can then be used in calls to
load_command_class(app_name, command_name)
If a specific version of a command must be loaded (e.g., with the
startapp command), the instantiated module can be placed in the
dictionary in place of the application name.
The dictionary is cached on the first call and reused on subsequent
calls.
"""
commands = {name: 'django.core' for name in find_commands(__path__[0])}
if not settings.configured:
return commands
for app_config in reversed(list(apps.get_app_configs())):
path = os.path.join(app_config.path, 'management')
commands.update({name: app_config.name for name in find_commands(path)})
return commands
示例15: main_help_text
# 需要导入模块: from django.conf import settings [as 别名]
# 或者: from django.conf.settings import configured [as 别名]
def main_help_text(self, commands_only=False):
"""Return the script's main help text, as a string."""
if commands_only:
usage = sorted(get_commands())
else:
usage = [
"",
"Type '%s help <subcommand>' for help on a specific subcommand." % self.prog_name,
"",
"Available subcommands:",
]
commands_dict = defaultdict(lambda: [])
for name, app in get_commands().items():
if app == 'django.core':
app = 'django'
else:
app = app.rpartition('.')[-1]
commands_dict[app].append(name)
style = color_style()
for app in sorted(commands_dict):
usage.append("")
usage.append(style.NOTICE("[%s]" % app))
for name in sorted(commands_dict[app]):
usage.append(" %s" % name)
# Output an extra note if settings are not properly configured
if self.settings_exception is not None:
usage.append(style.NOTICE(
"Note that only Django core commands are listed "
"as settings are not properly configured (error: %s)."
% self.settings_exception))
return '\n'.join(usage)