打包上传的2.0版本

This commit is contained in:
YueL1331
2026-01-09 12:48:50 +08:00
parent ca895af384
commit ffbd494b7b
14 changed files with 240 additions and 162 deletions

27
2_1banben/routes/web.py Normal file
View File

@ -0,0 +1,27 @@
import os
from flask import Blueprint, send_from_directory
# 👇 确保 config.py 在根目录,且能被引用
from config import get_static_path
web_bp = Blueprint('web', __name__)
@web_bp.route('/')
def index():
"""访问根路径时,返回 dist/index.html"""
try:
return send_from_directory(get_static_path(), 'index.html')
except Exception as e:
return f"前端资源未找到,请确认 dist 文件夹是否存在。错误信息: {e}", 404
@web_bp.route('/<path:path>')
def static_files(path):
"""访问 /css, /js 等静态资源"""
static_folder = get_static_path()
file_path = os.path.join(static_folder, path)
if os.path.exists(file_path):
return send_from_directory(static_folder, path)
# 路由回退:解决 Vue History 模式刷新 404 问题
# 如果找不到文件,就返回 index.html让 Vue 路由去处理
return send_from_directory(static_folder, 'index.html')