本文整理匯總了Python中django.conf.settings.PROJECT_ROOT屬性的典型用法代碼示例。如果您正苦於以下問題:Python settings.PROJECT_ROOT屬性的具體用法?Python settings.PROJECT_ROOT怎麽用?Python settings.PROJECT_ROOT使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在類django.conf.settings
的用法示例。
在下文中一共展示了settings.PROJECT_ROOT屬性的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: handle
# 需要導入模塊: from django.conf import settings [as 別名]
# 或者: from django.conf.settings import PROJECT_ROOT [as 別名]
def handle(self, *args, **options):
module = options['module']
if module not in self.importers:
raise CommandError("Importer %s not found. Valid importers: %s" % (module, self.imp_list))
imp_class = self.importers[module]
if hasattr(settings, 'PROJECT_ROOT'):
root_dir = settings.PROJECT_ROOT
else:
root_dir = settings.BASE_DIR
importer = imp_class({'data_path': os.path.join(root_dir, 'data'),
'verbosity': int(options['verbosity']),
'cached': options['cached'],
'single': options['single'],
'remap': options['remap'],
'force': options['force']})
# Activate the default language for the duration of the import
# to make sure translated fields are populated correctly.
old_lang = get_language()
activate(settings.LANGUAGES[0][0])
for imp_type in self.importer_types:
name = "import_%s" % imp_type
method = getattr(importer, name, None)
if options[imp_type]:
if not method:
raise CommandError("Importer {} does not support importing {}".format(importer.name, imp_type))
if imp_type == 'courses' and 'extension_course' not in settings.INSTALLED_APPS:
raise CommandError("Course extension must be installed when importing courses.")
else:
if not options['all']:
continue
if method:
method()
activate(old_lang)
示例2: handle
# 需要導入模塊: from django.conf import settings [as 別名]
# 或者: from django.conf.settings import PROJECT_ROOT [as 別名]
def handle(self, **options):
media_src_dir = os.path.join(settings.PROJECT_ROOT, 'pages', 'media')
image_src_dir = os.path.join(media_src_dir, 'images')
image_src_dir_or = os.path.join(media_src_dir, 'original_images')
documents_src_dir = os.path.join(media_src_dir, 'documents')
image_dest_dir_or = os.path.join(settings.MEDIA_ROOT,
'original_images')
image_dest_dir = os.path.join(settings.MEDIA_ROOT, 'images')
documents_dest_dir = os.path.join(settings.MEDIA_ROOT, 'documents')
if not os.path.isdir(image_dest_dir):
os.makedirs(image_dest_dir)
for filename in os.listdir(image_src_dir):
shutil.copy(os.path.join(image_src_dir, filename), image_dest_dir)
if not os.path.isdir(image_dest_dir_or):
os.makedirs(image_dest_dir_or)
for filename in os.listdir(image_src_dir_or):
shutil.copy(
os.path.join(image_src_dir_or, filename), image_dest_dir_or
)
if not os.path.isdir(documents_dest_dir):
os.makedirs(documents_dest_dir)
for filename in os.listdir(documents_src_dir):
shutil.copy(
os.path.join(documents_src_dir, filename), documents_dest_dir
)
示例3: handle
# 需要導入模塊: from django.conf import settings [as 別名]
# 或者: from django.conf.settings import PROJECT_ROOT [as 別名]
def handle(self, *args, **options):
fixtures_dir = os.path.join(settings.PROJECT_ROOT, settings.SITE_NAME, 'core', 'fixtures')
fixture_file = os.path.join(fixtures_dir, 'initial_data.json')
image_src_dir = os.path.join(fixtures_dir, 'images')
image_dest_dir = os.path.join(settings.MEDIA_ROOT, 'original_images')
call_command('loaddata', fixture_file, verbosity=3)
if not os.path.isdir(image_dest_dir):
os.makedirs(image_dest_dir)
for filename in os.listdir(image_src_dir):
shutil.copy(os.path.join(image_src_dir, filename), image_dest_dir)
示例4: execute_command
# 需要導入模塊: from django.conf import settings [as 別名]
# 或者: from django.conf.settings import PROJECT_ROOT [as 別名]
def execute_command(self, command):
project_dir = None
if hasattr(settings, 'BASE_DIR'):
project_dir = settings.BASE_DIR
elif hasattr(settings, 'PROJECT_ROOT'):
project_dir = settings.PROJECT_ROOT
elif hasattr(settings, 'APP_ROOT'):
project_dir = settings.APP_ROOT
manage_py = os.path.join(project_dir, 'manage.py')
process = subprocess.Popen(
"{} {} {}".format(executable, manage_py, command), shell=True)
out, err = process.communicate()
logger.info(out)
logger.error(err)