12345678910111213141516171819202122 |
- from flask import Flask, jsonify
- import pandas as pd
- from flask_cors import CORS
- # 创建 Flask 应用
- app = Flask(__name__)
- # 启用 CORS
- CORS(app)
- @app.route('/data', methods=['GET'])
- def get_data():
- try:
- # 读取 CSV 文件,忽略索引列
- df = pd.read_csv('url.csv', index_col=0)
- data = df.to_dict(orient='records') # 转换为字典列表
- return jsonify(data), 200
- except Exception as e:
- return jsonify({"error": str(e)}), 500
- if __name__ == '__main__':
- app.run(debug=True)
|