Issue
I have this table in Flask:
<tbody>
{% for record in records %}
<tr>
<td onclick=search_results()>{{ record.id }}</td>
<td>{{ record.contractor }}</td>
<td>{{ record.category }}</td>
<td><A HREF='tel:{{ record.phone }}'>{{ record.phone }}</A></td>
</tr>
{% endfor %}
</tbody>
And this function:
@app.route('/detail/<id>')
def search_results(id):
records = db.session.query(Feedback).filter(Feedback.id == id)
print('search')
for record in records:
print(record)
return render_template('pageDetail.html', records=records)
I have researched similar questions but struggling still to understand how I can pass the id number of the selected cell to the search_results function.
Thank you in advance!
Solution
You need to hit the endpoint from the html and not the function call, try doing this,
<tbody>
{% for record in records %}
<tr>
<td href='/detail/{{ record.id }}'>{{ record.id }}</td>
<td>{{ record.contractor }}</td>
<td>{{ record.category }}</td>
<td><A HREF='tel:{{ record.phone }}'>{{ record.phone }}</A></td>
</tr>
{% endfor %}
</tbody>
Your flask view is fine.
Answered By - Harris Minhas
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.