I see this on web, I want to try myself but stock
- .py
(can get sql data and pass on index_test_0203.html)
import mysql.connector
import webbrowser
import time
import pymysql
from flask import Flask,render_template,request
app = Flask(__name__)
mydb = mysql.connector.connect(
host="196.168.1.141",
user="Main_root",
password="password_123",
database="database_db",
auth_plugin='mysql_native_password'
)
mycursor = mydb.cursor()
mycursor.execute("SELECT P_TITLE,P_DESC FROM webpage WHERE P_ID = "+request.args["P_ID"])
myresult = mycursor.fetchall()
print(myresult)
@app.route('/')
def index():
return render_template("index_test_0203.html", myresult = myresult)
if __name__ == "__main__":
app.run(debug=True)
- index_test_0203.html
(can get text by flask from url to html document.write(p) )
but lacking pass that text to .py as certain P_ID to search, and activate .py
<!DOCTYPE html>
<html>
<script type="text/javascript">
const queryString = window.location.search;
const urlParams = new URLSearchParams(queryString);
for (const p of urlParams) {
document.write(p+'<br/>');
}
</script>
<body>
<p> this is {{myresult}}</p>
</body>
</html>
[(demo pic) the activate order](https://i.stack.imgur.com/Xadkt.png) please take a look
[(the original pic)](https://i.stack.imgur.com/xuB5q.png)
I will put both .py and .html on cloud server
What I have tried:
- main idea:
how to trigger/activate .py file from .html url, such as `http://192.168.0.206:8080/english/index_test_0203.html?P_ID=en-1-01`
what I have studied for now is that maybe ajax or flask could help, if get any suggestion just let me know, I'm happy to learn new thing, and in order to fix this problem