sc.py 537 B

12345678910111213141516171819202122
  1. from flask import Flask, jsonify
  2. import pandas as pd
  3. from flask_cors import CORS
  4. # 创建 Flask 应用
  5. app = Flask(__name__)
  6. # 启用 CORS
  7. CORS(app)
  8. @app.route('/data', methods=['GET'])
  9. def get_data():
  10. try:
  11. # 读取 CSV 文件,忽略索引列
  12. df = pd.read_csv('url.csv', index_col=0)
  13. data = df.to_dict(orient='records') # 转换为字典列表
  14. return jsonify(data), 200
  15. except Exception as e:
  16. return jsonify({"error": str(e)}), 500
  17. if __name__ == '__main__':
  18. app.run(debug=True)