Ok, I've been trying to do this for almost 10 hours now, and I can't figure it out. I have a restaurant search app, which works when printing the output to the terminal, but I have no idea how to get it to print on a new page. This is what I have so far:
@app.route('/')
def results(area, rating, food):
conn = sqlite3.connect('SRG.db')
c = conn.cursor()
c.execute('SELECT * FROM restaurants WHERE address LIKE "%%%s%%" \
AND rating > %s-1 AND type LIKE "%%%s%%" ORDER BY rating DESC' \
% (area, rating, food,))
while True:
row = c.fetchone()
if row == None:
break
print 'Name: ',row[1]
print 'Rating: ',row[3]
print 'Price: ',row[2]
print 'Type: ',row[4]
print 'Website: ',row[5]
print 'Address: ',row[6]
print 'Subway: ',row[7]
print 'Phone: ',row[8],'\n'
return render_template('results.html', row=row)
Now, that part works and prints to the terminal. I have a problem printing it to an html page. This is the template that I have so far:
<head>
<meta charset="UTF-8">
<title>Here are your results</title>
</head>
<body>
<h1>Check out these restaurants</h1>
<ul>
{% for row in results %}
<p>Name: {{ row[1] }}</p>
<p>Rating: {{ row[3] }}</p>
<p>Price: {{ row[2] }}</p>
<p>Type: {{ row[4] }}</p>
<p>Website: {{ row[5] }}</p>
<p>Address: {{ row[6] }}</p>
<p>Subway: {{ row[7] }}</p>
<p>Phone: {{ row[8] }}</p>
{% endfor %}
<p><em>Sorry, no restaurants fit that criteria</em></p>
</ul>
</body>
</html>
Could someone please help? I feel like it is something minor and it is driving me crazy! It would be the best Christmas present ever!
Aucun commentaire:
Enregistrer un commentaire