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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import os
import sys
import django
 
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'backend.settings')
django.setup()
 
from django.core.management import call_command
 
 
def collect_static():
    """
    收集静态文件
    """
    print("=" * 60)
    print("开始收集静态文件...")
    print("=" * 60)
 
    try:
        call_command('collectstatic', '--noinput', verbosity=2)
        print("\n✓ 静态文件收集完成!")
        return True
 
    except Exception as e:
        print(f"\n✗ 静态文件收集失败: {e}")
        import traceback
        traceback.print_exc()
        return False
 
 
def create_superuser():
    """
    交互式创建超级用户
    """
    print("\n" + "=" * 60)
    print("创建超级用户 (可选)")
    print("=" * 60)
    print("如需创建超级用户,请按 Ctrl+C 取消,然后单独运行 create_admin_user.py")
    print()
 
    try:
        call_command('createsuperuser')
        return True
    except KeyboardInterrupt:
        print("\n跳过创建超级用户")
        return True
    except Exception as e:
        print(f"创建超级用户失败: {e}")
        return False
 
 
if __name__ == '__main__':
    success = collect_static()
    if success:
        create_superuser()
        sys.exit(0)
    else:
        sys.exit(1)