【发布时间】:2021-10-29 11:51:04
【问题描述】:
我不是程序员,我正在努力学习并将其用于作业。我需要使用烧瓶休息 API 来搜索数据并将数据从 CSV 文件提取到页面。目标是让用户在 /logcheck/
CSV 样本和位置 /家/日志/ 以及 CSV 文件内容的示例截图如下: [在此处输入图片描述][1] [1]:https://i.stack.imgur.com/GQpDb.png
烧瓶代码如下:
import csv
from io import StringIO
import sys
from flask import Flask, request, send_file, jsonify, Response, render_template
from flask.helpers import make_response
csv_file = csv.reader(open('/home/logs/containerlogs.csv', "r"), delimiter=",")
@app.route('/logcheck/<user_input>', methods=['GET'])
def logcheck(user_input):
healthy = request.form ['healthy']
unhealthy = request.form ['unhealthy']
if user_input not healthy or not unhealthy:
return make_response("Please try again./n Only word /logcheck/healthy or logcheck/unhealthy)
else:
for row in csv_file:
if user_input == row[0 or 1 or 2 or 3 or 4 or 5]:
return make_response (print (row))
提前致谢。
【问题讨论】: