-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcheck_env.py
More file actions
38 lines (29 loc) · 806 Bytes
/
check_env.py
File metadata and controls
38 lines (29 loc) · 806 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import os
from pathlib import Path
from dotenv import load_dotenv
import sys
BASE_DIR = Path(__file__).resolve().parent
env_name = os.getenv("DJANGO_ENV", ".env.sample")
env_file = BASE_DIR / f".env.{env_name}"
if not env_file.exists():
print(f"❌ Missing env file: {env_file}")
sys.exit(1)
print(f"🔍 Loading environment: {env_file}")
load_dotenv(env_file)
# 必填项(按环境可扩展)
required_vars = [
"DJANGO_SECRET_KEY",
"DEBUG",
"DB_NAME",
"DB_USER",
"DB_PASSWORD",
"DB_HOST",
"DB_PORT",
"ALLOWED_HOSTS",
"CSRF_TRUSTED_ORIGINS",
]
missing = [var for var in required_vars if not os.getenv(var)]
if missing:
print(f"❌ Missing required variables: {', '.join(missing)}")
sys.exit(1)
print("✅ All required env variables are set.")