當前位置: 首頁>>代碼示例>>Python>>正文


Python apps.ready方法代碼示例

本文整理匯總了Python中django.apps.apps.ready方法的典型用法代碼示例。如果您正苦於以下問題:Python apps.ready方法的具體用法?Python apps.ready怎麽用?Python apps.ready使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在django.apps.apps的用法示例。


在下文中一共展示了apps.ready方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: setup_django

# 需要導入模塊: from django.apps import apps [as 別名]
# 或者: from django.apps.apps import ready [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() 
開發者ID:tokibito,項目名稱:django-ftpserver,代碼行數:27,代碼來源:conf.py

示例2: mock_django_setup

# 需要導入模塊: from django.apps import apps [as 別名]
# 或者: from django.apps.apps import ready [as 別名]
def mock_django_setup(settings_module, disabled_features=None):
    """ Must be called *AT IMPORT TIME* to pretend that Django is set up.

    This is useful for running tests without using the Django test runner.
    This must be called before any Django models are imported, or they will
    complain. Call this from a module in the calling project at import time,
    then be sure to import that module at the start of all mock test modules.
    Another option is to call it from the test package's init file, so it runs
    before all the test modules are imported.
    :param settings_module: the module name of the Django settings file,
        like 'myapp.settings'
    :param disabled_features: a list of strings that should be marked as
        *False* on the connection features list. All others will default
        to True.
    """
    if apps.ready:
        # We're running in a real Django unit test, don't do anything.
        return

    if 'DJANGO_SETTINGS_MODULE' not in os.environ:
        os.environ['DJANGO_SETTINGS_MODULE'] = settings_module
    django.setup()
    mock_django_connection(disabled_features) 
開發者ID:stphivos,項目名稱:django-mock-queries,代碼行數:25,代碼來源:mocks.py

示例3: model_unpickle

# 需要導入模塊: from django.apps import apps [as 別名]
# 或者: from django.apps.apps import ready [as 別名]
def model_unpickle(model_id, attrs, factory):
    """
    Used to unpickle Model subclasses with deferred fields.
    """
    if isinstance(model_id, tuple):
        if not apps.ready:
            apps.populate(settings.INSTALLED_APPS)
        model = apps.get_model(*model_id)
    else:
        # Backwards compat - the model was cached directly in earlier versions.
        model = model_id
    cls = factory(model, attrs)
    return cls.__new__(cls) 
開發者ID:lanbing510,項目名稱:GTDWeb,代碼行數:15,代碼來源:base.py

示例4: _django_setup

# 需要導入模塊: from django.apps import apps [as 別名]
# 或者: from django.apps.apps import ready [as 別名]
def _django_setup():
    os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'rssant.settings')
    if not apps.ready and not settings.configured:
        django.setup() 
開發者ID:anyant,項目名稱:rssant,代碼行數:6,代碼來源:django_setup.py

示例5: check_debug

# 需要導入模塊: from django.apps import apps [as 別名]
# 或者: from django.apps.apps import ready [as 別名]
def check_debug():
    """Check that Django's template debugging is enabled.

    Django's built-in "template debugging" records information the plugin needs
    to do its work.  Check that the setting is correct, and raise an exception
    if it is not.

    Returns True if the debug check was performed, False otherwise
    """
    from django.conf import settings

    if not settings.configured:
        return False

    # I _think_ this check is all that's needed and the 3 "hasattr" checks
    # below can be removed, but it's not clear how to verify that
    from django.apps import apps
    if not apps.ready:
        return False

    # django.template.backends.django gets loaded lazily, so return false
    # until they've been loaded
    if not hasattr(django.template, "backends"):
        return False
    if not hasattr(django.template.backends, "django"):
        return False
    if not hasattr(django.template.backends.django, "DjangoTemplates"):
        raise DjangoTemplatePluginException("Can't use non-Django templates.")

    for engine in django.template.engines.all():
        if not isinstance(engine, django.template.backends.django.DjangoTemplates):
            raise DjangoTemplatePluginException(
                "Can't use non-Django templates."
            )
        if not engine.engine.debug:
            raise DjangoTemplatePluginException(
                "Template debugging must be enabled in settings."
            )

    return True 
開發者ID:nedbat,項目名稱:django_coverage_plugin,代碼行數:42,代碼來源:plugin.py

示例6: test_ready

# 需要導入模塊: from django.apps import apps [as 別名]
# 或者: from django.apps.apps import ready [as 別名]
def test_ready(self):
        """
        Tests the ready property of the master registry.
        """
        # The master app registry is always ready when the tests run.
        self.assertIs(apps.ready, True)
        # Non-master app registries are populated in __init__.
        self.assertIs(Apps().ready, True) 
開發者ID:nesdis,項目名稱:djongo,代碼行數:10,代碼來源:tests.py


注:本文中的django.apps.apps.ready方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。