本文整理汇总了Python中django.utils.module_loading.import_module方法的典型用法代码示例。如果您正苦于以下问题:Python module_loading.import_module方法的具体用法?Python module_loading.import_module怎么用?Python module_loading.import_module使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类django.utils.module_loading
的用法示例。
在下文中一共展示了module_loading.import_module方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: import_crud
# 需要导入模块: from django.utils import module_loading [as 别名]
# 或者: from django.utils.module_loading import import_module [as 别名]
def import_crud(app):
'''
Import crud module and register all model cruds which it contains
'''
try:
app_path = import_module(app).__path__
except (AttributeError, ImportError):
return None
try:
imp.find_module('crud', app_path)
except ImportError:
return None
module = import_module("%s.crud" % app)
return module
示例2: __init__
# 需要导入模块: from django.utils import module_loading [as 别名]
# 或者: from django.utils.module_loading import import_module [as 别名]
def __init__(self, method = 'GET'):
super(EnhancedHttpRequest, self).__init__()
self.method = method
session_engine = import_module(settings.SESSION_ENGINE)
self.session = session_engine.SessionStore(session_key = None)
示例3: create_session
# 需要导入模块: from django.utils import module_loading [as 别名]
# 或者: from django.utils.module_loading import import_module [as 别名]
def create_session(self):
session_engine = import_module(settings.SESSION_ENGINE)
store = session_engine.SessionStore()
store.save()
self.client.cookies[settings.SESSION_COOKIE_NAME] = store.session_key
示例4: register_builtin_plugins
# 需要导入模块: from django.utils import module_loading [as 别名]
# 或者: from django.utils.module_loading import import_module [as 别名]
def register_builtin_plugins(site):
from django.conf import settings
from django.utils.module_loading import import_module
exclude_plugins = getattr(settings, 'XADMIN_EXCLUDE_PLUGINS', [])
try:
import formtools
except Exception:
exclude_plugins.append('wizard')
[import_module('xadmin.plugins.%s' % plugin) for plugin in PLUGINS if plugin not in exclude_plugins]
示例5: get_session_app
# 需要导入模块: from django.utils import module_loading [as 别名]
# 或者: from django.utils.module_loading import import_module [as 别名]
def get_session_app():
engine = import_module(settings.SESSION_ENGINE)
store = engine.SessionStore
if hasattr(store, "get_model_class"):
session_model = store.get_model_class()
if issubclass(session_model, AbstractBaseSession):
return session_model._meta.app_config.name
return None
示例6: autodiscover
# 需要导入模块: from django.utils import module_loading [as 别名]
# 或者: from django.utils.module_loading import import_module [as 别名]
def autodiscover():
"""
Auto-discover INSTALLED_APPS admin.py modules and fail silently when
not present. This forces an import on them to register any admin bits they
may want.
"""
from django.conf import settings
from django.utils.module_loading import module_has_submodule, import_module
setattr(settings, 'CRISPY_TEMPLATE_PACK', 'bootstrap3')
setattr(settings, 'CRISPY_CLASS_CONVERTERS', {
"textinput": "textinput textInput form-control",
"fileinput": "fileinput fileUpload form-control",
"passwordinput": "textinput textInput form-control",
})
from xadmin.views import register_builtin_views
register_builtin_views(site)
# load xadmin settings from XADMIN_CONF module
try:
xadmin_conf = getattr(settings, 'XADMIN_CONF', 'xadmin_conf.py')
conf_mod = import_module(xadmin_conf)
except Exception:
conf_mod = None
if conf_mod:
for key in dir(conf_mod):
setting = getattr(conf_mod, key)
try:
if issubclass(setting, Settings):
site.register_settings(setting.__name__, setting)
except Exception:
pass
from xadmin.plugins import register_builtin_plugins
register_builtin_plugins(site)
from django.apps import apps
for app_config in apps.get_app_configs():
# Attempt to import the app's admin module.
try:
before_import_registry = site.copy_registry()
import_module('%s.adminx' % app_config.name)
except:
# Reset the model registry to the state before the last import as
# this import will have to reoccur on the next request and this
# could raise NotRegistered and AlreadyRegistered exceptions
# (see #8245).
site.restore_registry(before_import_registry)
# Decide whether to bubble up this error. If the app just
# doesn't have an admin module, we can ignore the error
# attempting to import it, otherwise we want it to bubble up.
if module_has_submodule(app_config.module, 'adminx'):
raise