Files

30 lines
1.2 KiB
Python

#!/usr/bin/env python
import os
import sys
sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
def main():
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
os.environ['DJANGO_SETTINGS_MODULE'] = 'ATestCServer.settings'
os.environ['DB_NAME'] = 'atestc'
# 安全:禁止硬编码默认密钥/口令,缺失时显式报错(settings.py 亦有
# ImproperlyConfigured 兜底)。MSYNC_SERVICE_SECRET 与 DB_PASSWORD
# 由部署环境(环境变量)提供。
required_envs = ['DJANGO_SECRET_KEY', 'MSYNC_SERVICE_SECRET', 'DB_PASSWORD']
missing = [name for name in required_envs if not os.environ.get(name)]
if missing:
raise SystemExit(
'缺少必需的环境变量: ' + ', '.join(missing)
+ '(禁止使用默认值,请通过环境变量注入)'
)
try:
from django.core.management import execute_from_command_line
except ImportError as exc:
raise ImportError(
"Couldn't import Django. Make sure it's installed and available."
) from exc
execute_from_command_line(sys.argv)
if __name__ == '__main__':
main()