student_server/all_server_open.py
2025-12-09 11:28:23 +08:00

42 lines
1.2 KiB
Python
Executable File
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

from flask import Flask, jsonify
from flask_cors import CORS
import json
from decimal import Decimal
from datetime import datetime, date
# 导入蓝图
from example_info_add import example_info_add_bp
from user_add import user_add_bp
from example_ai_info import example_info_ai_bp
# 极简JSON编码器处理特殊数据类型
class CustomJSONEncoder(json.JSONEncoder):
def default(self, obj):
if isinstance(obj, Decimal):
return float(obj)
elif isinstance(obj, (datetime, date)):
return obj.strftime('%Y-%m-%d %H:%M:%S')
return super().default(obj)
# 创建单个Flask应用
app = Flask(__name__)
CORS(app) # 允许跨域
app.json_encoder = CustomJSONEncoder
app.config['JSON_SORT_KEYS'] = False
# 注册所有蓝图
app.register_blueprint(example_info_add_bp)
app.register_blueprint(example_info_ai_bp)
app.register_blueprint(user_add_bp)
if __name__ == '__main__':
# 配置服务(直接修改端口)
host = '0.0.0.0'
port = 5000
print(f"服务启动http://{host}:{port}")
print("按 Ctrl+C 停止服务...")
app.run(host=host, port=port, debug=False) # debug=False 生产环境推荐