Click here to Skip to main content
15,940,550 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I see this on web, I want to try myself but stock

- .py
(can get sql data and pass on index_test_0203.html)
Python
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()

# below one can work that exectue pyscript with fixed P_ID = 'en_1-01'
# mycursor.execute("SELECT P_TITLE,P_DESC  FROM webpage WHERE P_ID = 'en_1-01'")  

# this one won't work, want to get text from .html
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
HTML
<!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
Posted
Updated 3-Feb-23 7:25am
Comments
Richard MacCutchan 3-Feb-23 4:40am    
You need a webserver running on 192.168.0.206:8080 that can service that request. But your question is not very clear.
j ton 3-Feb-23 4:52am    
I both upload index_test_0203.html and .py to WinSCP, the cloud server, but just question on 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`
Richard MacCutchan 3-Feb-23 4:59am    
That is just a repeat of what you have posted above, and my answer remains the same. You need to explain exactly what the problem is.

Yes I trieed this solution in CMD prompt and this is the answer that it gave me, it gave me this as a result not to sure but I tried to execute the code and it didn't properly work out.


The code you provided would just give me a repeated error in the command prompt and tell me how the app.route is not a recognized interal or external command and there is no batch file..
 
Share this answer
 
I suggest you take a look at Welcome to Flask — Flask Documentation (2.2.x)[^], and work through the tutorial.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900