代码拉取完成,页面将自动刷新
from flask import request, Flask, send_from_directory, url_for, jsonify
import os
import datetime
basepath = r'F:\0.http'
app = Flask(__name__)
@app.route("/", methods=["GET"])
def index():
file_list = os.listdir(basepath)
text = ""
if len(file_list) != 0:
for i in file_list:
text = text + i + "\n"
else:
text = "root dir have not any file!\n"
return text
@app.route('/<path:filename>', methods=['GET'])
def download(filename):
file_list = os.listdir(basepath)
for file in file_list:
if filename in file:
return send_from_directory(basepath, file, as_attachment=True)
return "root dir have not file:{}\n".format(filename)
@app.route('/upload', methods=['POST'])
def upload_file():
f = request.files['file']
upload_path = os.path.join(basepath, f.filename)
f.save(upload_path)
url = url_for('upload_file', _external=True).replace(
"upload", "") + f.filename
return jsonify({'url': url})
@app.route('/getDate', methods=['POST', 'GET'])
def getDate():
return datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')
@app.route('/getUTCDate', methods=['POST', 'GET'])
def getUTCDate():
return datetime.datetime.utcnow().strftime('%Y-%m-%d %H:%M:%S')
if __name__ == '__main__':
app.run(host="0.0.0.0", port=80)
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。