Files
recommend/start_web.py

55 lines
1.4 KiB
Python
Raw Normal View History

# -*- coding: utf-8 -*-
"""
启动网页应用的脚本
"""
import sys
from pathlib import Path
# 添加项目根目录到Python路径
project_root = Path(__file__).parent
sys.path.insert(0, str(project_root))
def check_flask():
"""检查Flask是否已安装"""
try:
import flask
print(f"✓ Flask已安装 (版本: {flask.__version__})")
return True
except ImportError:
print("✗ Flask未安装请运行: pip install Flask")
return False
def main():
if not check_flask():
return False
# 创建必要的目录
Path('templates').mkdir(exist_ok=True)
Path('static/css').mkdir(parents=True, exist_ok=True)
Path('static/js').mkdir(parents=True, exist_ok=True)
Path('logs').mkdir(exist_ok=True)
print("\n🚀 正在启动网页服务器...")
print("=" * 50)
2025-11-05 13:32:14 +08:00
print("📱 访问地址: http://localhost:7400")
print("📝 背诵排序: http://localhost:7400/recitation")
print("\n按 Ctrl+C 停止服务器\n")
try:
from web_app import app
2025-11-05 13:32:14 +08:00
app.run(debug=True, host='0.0.0.0', port=7400)
except KeyboardInterrupt:
print("\n👋 服务器已停止")
except Exception as e:
print(f"\n❌ 启动失败: {e}")
return False
return True
if __name__ == "__main__":
success = main()
if not success:
sys.exit(1)