I'm trying to link html form with python and sql. My requirement is that the user gives an input and that input should be sent to some python function block to execute an sql statement on MS SQL Server and return the results back to the user. Please help in linking the below code : order.html
<html>
<form action="/order" method="POST">
<input type="text" name="month">
<input type="number" name="weekno">
<input type="submit">
</form>
The stock for {{weekno}} is xyz
</html>
order.py :
from flask import Flask,render_template
import sys
app = Flask(__name__)
@app.route('/order', method=['POST'])
def orderdb() :
# using sql server connection statement here
cursor = connection.cursor ()
cursor.execute ("select month,stock from salesdb where weeknumbr=?",weekno)
return render_template('order.html',weekno = weekno)
This is a sample code i'm using here instead of pasting complete code.
Please suggest the syntax to be used so that the query should take the weekno value from the form and execute the query based on weeknumbr condition.
Thanks!!