从 html 激活/执行 python 脚本(通过 url 而不是 submit 按钮)

现在我有 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
html>
<html>
    <body>
      <p> this is {{myresult}}p>

    body>
html>
  • 预期流程的简图

enter image description here

我之后会把 .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 脚本 是 "图片中的任务顺序”中间的步骤,我希望的流程是从第一步到最后一步

enter image description here


from flask import Flask,render_template,request   // 修改点


@app.route('/')
  def index():
      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 = "+request.args["ProductID"])         // 修改点              
                                         
    myresult = mycursor.fetchall()

    print(myresult)    # does get the result I want 
    return render_template("Myshop.html", myresult = myresult)

http://192.168.0.206:8080/english/MyShop.html?ProductID=001 或者 http://192.168.0.206:8080/english/MyShop.html?ProductID=002 等就可以动态更改

难道不应该直接修改app.route的值吗?

那要怎么让其他人连上这个网页, 然后藉由http://192.168.0.206:8080/english/MyShop.html?ProductID=001 或者 http://192.168.0.206:8080/english/MyShop.html?ProductID=002 更新网页内容
 
(没有去到不同网页,都在同网页,只是中间产品的文本不同)
 
目前看哥的网页还是要藉由启动 .py 脚本才能生成