现在我有 python 脚本可以提取 mysql 数据并传递给Myshop html
- .py 脚本
import mysql.connector
import webbrowser
import time
import pymysql
from flask import Flask,render_template
app = Flask(__name__)
mydb = mysql.connector.connect(
host="196.168.101.141",
user="root",
password="password123",
database="cool_db",
auth_plugin='mysql_native_password'
)
# assume customer looking for product ID 001 item
mycursor = mydb.cursor()
mycursor.execute("SELECT P_TITLE,P_PRICE FROM webpage WHERE P_ID = '001'")
myresult = mycursor.fetchall()
print(myresult) # does get the result I want
# send result to index.html
@app.route('/')
def index():
return render_template("Myshop.html", myresult = myresult)
if __name__ == "__main__":
app.run(debug=True)
- Myshop.html
<!DOCTYPE html>
<html>
<body>
<p> this is {{myresult}}</p>
</body>
</html>
- 预期流程的简图
我之后会把 .py 和 Myshop.html 都放到 WinSCP上(online),放到线上
问题:如何藉由输入像http://192.168.0.206:8080/english/MyShop.html?ProductID=001
这样的url来触发.py脚本
该网页可以用我的脚本显示不同的内容
我想使用 url 来传递值(http: ......product=001)并激活我的 .py 脚本来刷新 Myshop.html
补充,我的问题为
问题:如何通过输入像http://192.168.0.206:8080/english/MyShop.html?ProductID=001
这样的url来触发.py脚本,任何人都可以输入url http://......ProductID=001
, http://......ProductID=007
加载新页面
我目前直接启动 .py 脚本 是 "图片中的任务顺序”中间的步骤,我希望的流程是从第一步到最后一步