本文整理汇总了Python中django.conf.settings.INSTALLED_APPS属性的典型用法代码示例。如果您正苦于以下问题:Python settings.INSTALLED_APPS属性的具体用法?Python settings.INSTALLED_APPS怎么用?Python settings.INSTALLED_APPS使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类django.conf.settings
的用法示例。
在下文中一共展示了settings.INSTALLED_APPS属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _autodiscover
# 需要导入模块: from django.conf import settings [as 别名]
# 或者: from django.conf.settings import INSTALLED_APPS [as 别名]
def _autodiscover(recipes):
import copy
from django.conf import settings
try:
# py27 / py3 only
from importlib import import_module
except ImportError:
from django.utils.importlib import import_module
from django.utils.module_loading import module_has_submodule
for app in settings.INSTALLED_APPS:
mod = import_module(app)
try:
before_import_recipes = copy.copy(recipes)
import_module('%s.badgify_recipes' % app)
except Exception:
recipes = before_import_recipes
if module_has_submodule(mod, 'badgify_recipes'):
raise
示例2: render
# 需要导入模块: from django.conf import settings [as 别名]
# 或者: from django.conf.settings import INSTALLED_APPS [as 别名]
def render(self, context):
allowed = False
for app in self.apps:
if app.startswith('"') and app.endswith('"'):
app = app[1:-1]
if app.startswith("'") and app.endswith("'"):
app = app[1:-1]
if app in settings.INSTALLED_APPS:
allowed = True
else:
break
if allowed:
return self.nodelist_true.render(context)
else:
return self.nodelist_false.render(context)
示例3: active_status
# 需要导入模块: from django.conf import settings [as 别名]
# 或者: from django.conf.settings import INSTALLED_APPS [as 别名]
def active_status(self, request):
"""
This will only work if you have django-celery installed (for now).
In case you only need to work with status codes to find out if the
workers are up or not.
This will only work if we assume our db only contains "active workers".
To use this feature, you must ensure you use only named workers,
For example: "-n worker1@localhost:8000".
http://docs.celeryproject.org/en/latest/userguide/workers.html#starting-the-worker
"""
app_installed = "djcelery" in settings.INSTALLED_APPS
if not app_installed:
return Response(status=status.HTTP_501_NOT_IMPLEMENTED)
from djcelery.models import WorkerState
count_workers = WorkerState.objects.all().count()
result = self.inspect.active()
if result is not None and count_workers == len(result):
return Response(status=status.HTTP_200_OK)
return Response(status=status.HTTP_404_NOT_FOUND)
示例4: get_app_template_dir
# 需要导入模块: from django.conf import settings [as 别名]
# 或者: from django.conf.settings import INSTALLED_APPS [as 别名]
def get_app_template_dir(app_name):
"""Get the template directory for an application
We do not use django.db.models.get_app, because this will fail if an
app does not have any models.
Returns a full path, or None if the app was not found.
"""
from django.conf import settings
from importlib import import_module
if app_name in _cache:
return _cache[app_name]
template_dir = None
for app in settings.INSTALLED_APPS:
if app.split('.')[-1] == app_name:
# Do not hide import errors; these should never happen at this point
# anyway
mod = import_module(app)
template_dir = join(abspath(dirname(mod.__file__)), 'templates')
break
_cache[app_name] = template_dir
return template_dir
示例5: setup
# 需要导入模块: from django.conf import settings [as 别名]
# 或者: from django.conf.settings import INSTALLED_APPS [as 别名]
def setup(set_prefix=True):
"""
Configure the settings (this happens as a side effect of accessing the
first setting), configure logging and populate the app registry.
Set the thread-local urlresolvers script prefix if `set_prefix` is True.
"""
from django.apps import apps
from django.conf import settings
from django.urls import set_script_prefix
from django.utils.log import configure_logging
configure_logging(settings.LOGGING_CONFIG, settings.LOGGING)
if set_prefix:
set_script_prefix(
'/' if settings.FORCE_SCRIPT_NAME is None else settings.FORCE_SCRIPT_NAME
)
apps.populate(settings.INSTALLED_APPS)
示例6: handle
# 需要导入模块: from django.conf import settings [as 别名]
# 或者: from django.conf.settings import INSTALLED_APPS [as 别名]
def handle(self, *args, **options):
self.sync_tenant = options.get('tenant')
self.sync_public = options.get('shared')
self.schema_name = options.get('schema_name')
self.executor = options.get('executor')
self.installed_apps = settings.INSTALLED_APPS
self.args = args
self.options = options
if self.schema_name:
if self.sync_public:
raise CommandError("schema should only be used with the --tenant switch.")
elif self.schema_name == get_public_schema_name():
self.sync_public = True
else:
self.sync_tenant = True
elif not self.sync_public and not self.sync_tenant:
# no options set, sync both
self.sync_tenant = True
self.sync_public = True
if hasattr(settings, 'TENANT_APPS'):
self.tenant_apps = settings.TENANT_APPS
if hasattr(settings, 'SHARED_APPS'):
self.shared_apps = settings.SHARED_APPS
示例7: test_medias_method_with_grappelli
# 需要导入模块: from django.conf import settings [as 别名]
# 或者: from django.conf.settings import INSTALLED_APPS [as 别名]
def test_medias_method_with_grappelli(self):
"""
Tests if the right css ile is triggered when grappelli is installed.
"""
try:
import grappelli
except ImportError:
return
settings.INSTALLED_APPS += ('grappelli', )
self.assertIn('grappelli', settings.INSTALLED_APPS)
admin = BandAdmin(Band, self.site)
medias = admin.media
self.assertTrue(len(medias._css) > 0)
self.assertIn('all', medias._css)
self.assertTrue(len(medias._css['all']) == 1)
self.assertIn('grappelli', medias._css['all'][0])
示例8: check_crequest
# 需要导入模块: from django.conf import settings [as 别名]
# 或者: from django.conf.settings import INSTALLED_APPS [as 别名]
def check_crequest(app_configs=None, **kwargs):
errors = []
if 'crequest' not in settings.INSTALLED_APPS:
errors.append(
Error('crequest app is missing',
hint='Add `crequest` to INSTALLED_APPS',
obj='settings',
id='ra.E003',
)
)
if 'crequest.middleware.CrequestMiddleware' not in settings.MIDDLEWARE:
errors.append(
Error('crequest middleware is missing',
hint='Add "crequest.middleware.CrequestMiddleware" to MIDDLEWARE',
obj='settings',
id='ra.E003',
)
)
return errors
示例9: main
# 需要导入模块: from django.conf import settings [as 别名]
# 或者: from django.conf.settings import INSTALLED_APPS [as 别名]
def main():
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "yawn.settings.debug")
# check if yawn is in installed apps, and bail if it is not
if 'yawn' not in settings.INSTALLED_APPS:
print("Please check your DJANGO_SETTINGS_MODULE environment variable.\n"
"Make sure 'yawn' is in your INSTALLED_APPS.\n"
"Generally, your settings file should start with 'from yawn.settings.base import *'")
sys.exit(1)
print('YAWN workflow management tool')
if os.environ['DJANGO_SETTINGS_MODULE'] == 'yawn.settings.debug':
print(' Running in DEBUG mode')
# run the django manage.py command line
execute_from_command_line(sys.argv)
示例10: get
# 需要导入模块: from django.conf import settings [as 别名]
# 或者: from django.conf.settings import INSTALLED_APPS [as 别名]
def get(self, request, *args, **kwargs):
"""
Django view get function.
Add items of extra_context, crumbs and grid to context.
Args:
request (): Django's request object.
*args (): request args.
**kwargs (): request kwargs.
Returns:
response: render to response with context.
"""
context = self.get_context_data(**kwargs)
context.update(self.extra_context)
context['crumbs'] = self.get_crumbs()
context['title'] = self.title
context['suit'] = 'suit' in settings.INSTALLED_APPS
if context.get('dashboard_grid', None) is None and self.grid:
context['dashboard_grid'] = self.grid
return self.render_to_response(context)
示例11: collect_plugins_in_apps
# 需要导入模块: from django.conf import settings [as 别名]
# 或者: from django.conf.settings import INSTALLED_APPS [as 别名]
def collect_plugins_in_apps(module_name: str, module_attr: str) -> Dict[str, Any]:
"""
Searches for [module_name].py in each app. If there is such module and it has
[module_attr] attribute in it then add it to the resulting dictionary with key = application name.
This way we can provide a pluggable architecture for various subsystems.
For example:
Documents app searches for "python_coded_fields.py" in each available app.
It takes PYTHON_CODED_FIELDS list from each found module and puts fields from it in the
big field registry.
"""
res = dict()
custom_apps = [i for i in settings.INSTALLED_APPS if i.startswith('apps.')]
for app_name in custom_apps:
module_str = '{0}.{1}'.format(app_name, module_name)
try:
app_module = importlib.import_module(module_str)
if hasattr(app_module, module_attr):
plugin = getattr(app_module, module_attr)
res[app_name] = plugin
except ImportError:
continue
return res
示例12: handle
# 需要导入模块: from django.conf import settings [as 别名]
# 或者: from django.conf.settings import INSTALLED_APPS [as 别名]
def handle(self, *args, **options):
# 1. remove migration files
custom_apps = [i.replace('apps.', '') for i in settings.INSTALLED_APPS if
i.startswith('apps.')]
for app_name in custom_apps:
app_migrations_path = os.path.join(settings.PROJECT_DIR, f'apps/{app_name}/migrations')
shutil.rmtree(app_migrations_path, ignore_errors=True)
# drop migrations table
with connection.cursor() as cursor:
cursor.execute('DROP TABLE django_migrations;')
# re-create migration files
call_command('makemigrations', 'common')
call_command('makemigrations')
# re-fill migrations
call_command('migrate', '--fake')
示例13: setup_dropdown
# 需要导入模块: from django.conf import settings [as 别名]
# 或者: from django.conf.settings import INSTALLED_APPS [as 别名]
def setup_dropdown(context):
if not SETUP_DROPDOWN:
for app_name in settings.INSTALLED_APPS:
app_shortname = app_name.rsplit('.', 1)[-1]
try:
url_module = import_module('{}.urls'.format(app_name))
except ImportError:
# TODO: ModuleNotFoundError for python >= 3.6
continue
setup_menu_cfg = getattr(url_module, 'setup_menu_cfg', None)
if not setup_menu_cfg:
logger.info('App %s w/o setup menu config', app_name)
continue
section_cfg = {'app_shortname': app_shortname,
'title': setup_menu_cfg.get('title', None) or app_shortname.title(),
'link_list': [],
'weight': setup_menu_cfg.get('weight', 1000)}
for url_name, anchor_text in setup_menu_cfg['items']:
section_cfg['link_list'].append((reverse('{}:{}'.format(app_shortname, url_name)),
anchor_text))
SETUP_DROPDOWN.append(section_cfg)
SETUP_DROPDOWN.sort(key=lambda d: (d['weight'], d['title']))
context["active"] = context.get("setup", False)
context["section_list"] = SETUP_DROPDOWN
return context
示例14: get_app_template_dir
# 需要导入模块: from django.conf import settings [as 别名]
# 或者: from django.conf.settings import INSTALLED_APPS [as 别名]
def get_app_template_dir(app_name):
"""
Get the template directory for an application
We do not use django.db.models.get_app, because this will fail if an
app does not have any models.
Returns a full path, or None if the app was not found.
"""
if app_name in _cache:
return _cache[app_name]
template_dir = None
for app in settings.INSTALLED_APPS:
if app.split('.')[-1] == app_name:
# Do not hide import errors; these should never happen at this
# point anyway
mod = import_module(app)
template_dir = join(abspath(dirname(mod.__file__)), 'templates')
break
_cache[app_name] = template_dir
return template_dir
示例15: setup
# 需要导入模块: from django.conf import settings [as 别名]
# 或者: from django.conf.settings import INSTALLED_APPS [as 别名]
def setup(set_prefix=True):
"""
Configure the settings (this happens as a side effect of accessing the
first setting), configure logging and populate the app registry.
Set the thread-local urlresolvers script prefix if `set_prefix` is True.
"""
from django.apps import apps
from django.conf import settings
from django.urls import set_script_prefix
from django.utils.encoding import force_text
from django.utils.log import configure_logging
configure_logging(settings.LOGGING_CONFIG, settings.LOGGING)
if set_prefix:
set_script_prefix(
'/' if settings.FORCE_SCRIPT_NAME is None else force_text(settings.FORCE_SCRIPT_NAME)
)
apps.populate(settings.INSTALLED_APPS)