1 Star 0 Fork 14

Joe/ant-learn-python-100P

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
p047_send_images_to_boss_server.py 1.05 KB
一键复制 编辑 原始数据 按行查看 历史
peiss 提交于 4年前 . 'xx'
import os
import flask
from flask import request
app = flask.Flask(__name__)
@app.route("/upload_images", methods=["GET", "POST"])
def upload_images():
if request.method == "POST":
file = request.files["file"]
# hostname = request.args.get("hostname")
dir_name = f"./static/boss_images"
if not os.path.exists(dir_name):
os.mkdir(dir_name)
file_name = f"{dir_name}/" + file.filename
print("收到文件:", file_name)
file.save(file_name)
return "success"
else:
return "success get"
@app.route("/query_images", methods=["GET"])
def query_images():
dir_name = "./static/boss_images"
html = "<html><body><ul>"
fnames = sorted([fname for fname in os.listdir(dir_name)
if fname.endswith(".png")], reverse=True)
for fname in fnames[:10]:
html += f"""
{fname}: <br/>
<img width='80%' src='{dir_name}/{fname}' />
<br /><br />
"""
html += "</ul></body></html>"
return html
app.run("0.0.0.0", 8888)
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Python
1
https://gitee.com/stayhungry2022/ant-learn-python-100P.git
git@gitee.com:stayhungry2022/ant-learn-python-100P.git
stayhungry2022
ant-learn-python-100P
ant-learn-python-100P
master

搜索帮助