Skip to content

Instantly share code, notes, and snippets.

@CN-CODEGOD
Created September 15, 2025 14:14
Show Gist options
  • Save CN-CODEGOD/3793a8445538c8cbee5cebff808be1f5 to your computer and use it in GitHub Desktop.
Save CN-CODEGOD/3793a8445538c8cbee5cebff808be1f5 to your computer and use it in GitHub Desktop.
利用flask简单做一个API 网页
1.
pip install flask
2.
from flask import Flask
import subprocess
app = Flask(__name__)
@app.route("/run")
def run():
result = subprocess.getoutput("python3 myscript.py")
return {"output": result}
app.run(host="0.0.0.0", port=8000)
3.
运行 python3 server.py
4.
在http://(IPaddress):8000/run 即可以查看你的脚本运行
用做API 执行
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment