初始提交:企业级日报系统完整代码
功能特性: - JWT用户认证系统 - 日报CRUD管理 - 三级权限控制 - 多维度搜索过滤 - 统计分析功能 - 评论互动系统 - 响应式Cool Admin界面 - 暗色主题支持 技术栈: - 后端:Django 4.2.7 + DRF + SimpleJWT - 前端:Vue 3 + Element Plus + Pinia - 数据库:SQLite/PostgreSQL - 部署:Docker + Nginx 包含内容: - 完整的后端API代码 - 现代化前端界面 - 数据库迁移文件 - 部署脚本和文档 - 演示页面和测试工具
This commit is contained in:
88
backend/deploy.py
Normal file
88
backend/deploy.py
Normal file
@@ -0,0 +1,88 @@
|
||||
#!/usr/bin/env python
|
||||
"""
|
||||
部署脚本 - 自动化部署Django应用
|
||||
"""
|
||||
import os
|
||||
import sys
|
||||
import subprocess
|
||||
import django
|
||||
|
||||
# 设置Django环境
|
||||
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'config.settings')
|
||||
django.setup()
|
||||
|
||||
def run_command(command, description):
|
||||
"""运行命令并处理错误"""
|
||||
print(f"\n{'='*50}")
|
||||
print(f"执行: {description}")
|
||||
print(f"命令: {command}")
|
||||
print(f"{'='*50}")
|
||||
|
||||
result = subprocess.run(command, shell=True, capture_output=True, text=True)
|
||||
|
||||
if result.returncode == 0:
|
||||
print(f"✅ {description} - 成功")
|
||||
if result.stdout:
|
||||
print(result.stdout)
|
||||
else:
|
||||
print(f"❌ {description} - 失败")
|
||||
if result.stderr:
|
||||
print(result.stderr)
|
||||
return False
|
||||
return True
|
||||
|
||||
def deploy():
|
||||
"""执行部署流程"""
|
||||
print("🚀 开始部署企业级日报系统后端...")
|
||||
|
||||
# 1. 检查Python版本
|
||||
if not run_command("python --version", "检查Python版本"):
|
||||
return False
|
||||
|
||||
# 2. 安装依赖
|
||||
if not run_command("pip install -r requirements.txt", "安装Python依赖"):
|
||||
return False
|
||||
|
||||
# 3. 数据库迁移
|
||||
if not run_command("python manage.py makemigrations", "生成数据库迁移文件"):
|
||||
return False
|
||||
|
||||
if not run_command("python manage.py migrate", "执行数据库迁移"):
|
||||
return False
|
||||
|
||||
# 4. 创建超级用户
|
||||
print("\n📝 创建超级用户和测试用户...")
|
||||
try:
|
||||
exec(open('create_superuser.py').read())
|
||||
print("✅ 用户创建完成")
|
||||
except Exception as e:
|
||||
print(f"❌ 创建用户失败: {e}")
|
||||
|
||||
# 5. 收集静态文件
|
||||
if not run_command("python manage.py collectstatic --noinput", "收集静态文件"):
|
||||
return False
|
||||
|
||||
# 6. 运行测试
|
||||
if not run_command("python manage.py check", "检查系统配置"):
|
||||
return False
|
||||
|
||||
print("\n🎉 后端部署完成!")
|
||||
print("\n📋 部署信息:")
|
||||
print("- 管理员账号: admin / admin123456")
|
||||
print("- 测试用户: zhangsan / test123456")
|
||||
print("- API地址: http://localhost:8000/api/")
|
||||
print("- 管理后台: http://localhost:8000/admin/")
|
||||
print("\n🚀 启动服务: python manage.py runserver")
|
||||
|
||||
return True
|
||||
|
||||
if __name__ == '__main__':
|
||||
try:
|
||||
success = deploy()
|
||||
sys.exit(0 if success else 1)
|
||||
except KeyboardInterrupt:
|
||||
print("\n\n⚠️ 部署被用户中断")
|
||||
sys.exit(1)
|
||||
except Exception as e:
|
||||
print(f"\n\n❌ 部署失败: {e}")
|
||||
sys.exit(1)
|
Reference in New Issue
Block a user