I'm very new to Python and Flask and I can't figure out why I don't have the list of data available to me here (ranked_list
is empty).
If I comment out all the Flask parts and just call getDataFromQuery
to get the data like a normal script, I can see the data and print it out. Can anyone see what I'm doing wrong? The data is a list of tuples. The index.html
page is below the code and it is in the templates
folder. All I get is a blank table with the header row.
from flask import Flask
from flask import render_template
from flask import request
from queryProcessing_and_Ranking import *
app = Flask(__name__)
@app.route("/")
@app.route("/<query>")
def index():
query = request.args.get("query")
Processing = QueryProcessing()
ranked_list = Processing.getDataFromQuery( query )
return render_template( "index.html", ranked_list = ranked_list, user_input = query )
if __name__ == '__main__':
port = int( os.environ.get('PORT', 5000 ) )
app.run( host='0.0.0.0', port=port, debug=True)
<html>
<head>
<title>Product Vertical Search Engine</title>
<link rel="stylesheet" type="text/css" href="{{ url_for('static', filename='style.css') }}">
</head>
<body>
<form>
Product Search: <input type="text" name="query"> <input type="Submit" value="Search">
</form>
<h1>Ranked product listing for: {{user_input}}</h1>
<table border = "1">
<tr>
<th>Title</th><th>Price</th>
</tr>
{% for item in ranked_list %}
<tr>
<td>{{item[0]}}</td>
</tr>
{% endfor %}
</table>
</body>
</html>