本文整理汇总了Python中django.core.management.utils.get_random_secret_key方法的典型用法代码示例。如果您正苦于以下问题:Python utils.get_random_secret_key方法的具体用法?Python utils.get_random_secret_key怎么用?Python utils.get_random_secret_key使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类django.core.management.utils
的用法示例。
在下文中一共展示了utils.get_random_secret_key方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: install_project
# 需要导入模块: from django.core.management import utils [as 别名]
# 或者: from django.core.management.utils import get_random_secret_key [as 别名]
def install_project(self):
self.info('开始安装DeerU')
self.info('下载DeerU ...')
s = ''
if os.path.exists(self.name):
# self.info('已存在相同目录 "%s" ,请选择: d(删除已存在目录); s(跳过下载) ' % self.name)
s = input('已存在相同目录 "%s" ,请选择: d(删除已存在目录); s(跳过下载): ' % self.name)
if s == 'd':
shutil.rmtree(self.name)
elif s == 's':
pass
else:
raise CommandError('输入错误')
if s != 's':
result = subprocess.run('git clone -b %s %s %s' % (self.branch, self.DEERU_GIT_URL, self.name), shell=True)
if result.returncode != 0:
raise CommandError('\n下载DeerU失败')
self.info('安装依赖...')
result = subprocess.run('pip install -r requirements.txt', cwd=self.name, shell=True)
if result.returncode != 0:
raise CommandError('\n安装依赖失败')
self.info('复制必要文件...')
context = Context({'SECRET_KEY': get_random_secret_key()}, autoescape=False)
for template_name, new_file in self.get_project_templates():
template = Engine().from_string(self.get_template_str(template_name))
content = template.render(context)
new_file.write_text(content)
self.success('\n安装完成 !!')
示例2: generate_secret_key
# 需要导入模块: from django.core.management import utils [as 别名]
# 或者: from django.core.management.utils import get_random_secret_key [as 别名]
def generate_secret_key(self):
self.status('Generating secret key... ')
self.context['SECRET_KEY'] = get_random_secret_key()
self.ok()
示例3: get_secret_from_file
# 需要导入模块: from django.core.management import utils [as 别名]
# 或者: from django.core.management.utils import get_random_secret_key [as 别名]
def get_secret_from_file(path):
try:
with open(path, "r") as f:
return f.read().strip()
except EnvironmentError:
with open(path, "w") as f:
secret_key = utils.get_random_secret_key()
f.write(secret_key)
return secret_key
示例4: generate_new
# 需要导入模块: from django.core.management import utils [as 别名]
# 或者: from django.core.management.utils import get_random_secret_key [as 别名]
def generate_new(self,
project_id: str,
project_name: str,
project_dir: str,
cloud_sql_connection: str,
database_name: Optional[str] = None,
cloud_storage_bucket_name: Optional[str] = None,
file_storage_bucket_name: Optional[str] = None):
"""Create Django settings file using our template.
Args:
project_id: GCP project id.
project_name: Name of the project to be created.
project_dir: The destination path to hold files of the project.
cloud_sql_connection: Connection string to allow the django app
to connect to the cloud sql proxy.
database_name: Name of your cloud database.
cloud_storage_bucket_name: Google Cloud Storage bucket name to
serve static content.
file_storage_bucket_name: Name of the Google Cloud Storage Bucket
used to store files by the Django app.
"""
database_name = database_name or project_name + '-db'
destination = os.path.join(
os.path.abspath(os.path.expanduser(project_dir)), project_name)
cloud_storage_bucket_name = cloud_storage_bucket_name or project_id
settings_templates_dir = os.path.join(self._get_template_folder_path(),
self._SETTINGS_TEMPLATE_DIRECTORY)
options = {
'project_id': project_id,
'project_name': project_name,
'docs_version': version.get_docs_version(),
'secret_key': django_utils.get_random_secret_key(),
'settings_module': 'settings',
'database_name': database_name,
'bucket_name': cloud_storage_bucket_name,
'file_bucket_name': file_storage_bucket_name,
'cloud_sql_connection': cloud_sql_connection
}
self._render_directory(settings_templates_dir,
destination,
options=options)
示例5: generate_from_existing
# 需要导入模块: from django.core.management import utils [as 别名]
# 或者: from django.core.management.utils import get_random_secret_key [as 别名]
def generate_from_existing(self,
project_id: str,
project_name: str,
cloud_sql_connection: str,
settings_path: str,
database_name: Optional[str] = None,
cloud_storage_bucket_name: Optional[str] = None,
file_storage_bucket_name: Optional[str] = None):
"""Create Django settings file from an existing settings file.
This is achieved by creating "cloud_settings.py" from our templates, and
make "cloud_settings.py" inherits the existing "settings.py", so the
existing settings file still have effects, and we only override what we
need to.
Args:
project_id: GCP project id.
project_name: Name of the project to be created.
cloud_sql_connection: Connection string to allow the django app
to connect to the cloud sql proxy.
settings_path: Absolute path of the settings.py used for deployment.
database_name: Name of your cloud database.
cloud_storage_bucket_name: Google Cloud Storage bucket name to
serve static content.
file_storage_bucket_name: Name of the Google Cloud Storage Bucket
used to store files by the Django app.
"""
database_name = database_name or project_name + '-db'
cloud_storage_bucket_name = cloud_storage_bucket_name or project_id
cloud_settings_template = os.path.join(
self._get_template_folder_path(), self._SETTINGS_TEMPLATE_DIRECTORY,
'cloud_settings.py-tpl')
settings_dir = os.path.dirname(settings_path)
root, _ = os.path.splitext(settings_path)
module_relative_path = os.path.relpath(root, settings_dir)
settings_module = module_relative_path.replace('/', '.')
options = {
'project_id': project_id,
'project_name': project_name,
'docs_version': version.get_docs_version(),
'secret_key': django_utils.get_random_secret_key(),
'settings_module': settings_module,
'database_name': database_name,
'bucket_name': cloud_storage_bucket_name,
'file_bucket_name': file_storage_bucket_name,
'cloud_sql_connection': cloud_sql_connection
}
settings_output_path = os.path.join(settings_dir, 'cloud_settings.py')
self._render_file(cloud_settings_template,
settings_output_path,
options=options)