我正在尝试为节目和场地制作一个搜索栏。我可以在带有选项 venue 或 show 的框中搜索,但我无法打印结果并且我的日志中没有错误。
@app.route('/search', methods = ['GET','POST'])
def search():
search_type = request.args.get('type')
query = request.args.get('q')
# Search for shows and venues that match the query
if search_type == 'venues':
search_results = Venue.query.filter(Venue.venue_name.ilike(f"%{query}%")).all()
elif search_type == 'shows':
search_results = Show.query.filter(Show.show_name.ilike(f"%{query}%")).all()
else:
search_results = []
这是我的 python 代码,但它正在打印一个空列表。
{% if results %}
<h2>Search Results for "{{ query }}"</h2>
{% if search_type == 'venues' %}
<ul>
{% for venue in results %}
<li><a href="/view_venues/{{ venue.venue_id }}">{{ venue.venue_name }}</a></li>
{% endfor %}
</ul>
{% elif search_type == 'shows' %}
<ul>
{% for show in results %}
<li><a href="/view_shows/{{ show.show_id }}">{{ show.show_name }}</a></li>
{% endfor %}
</ul>
{% endif %}
{% endif %}
这是我的 html 代码,其中应显示场地或节目列表。你能帮我解决这个错误吗?我得到的只是两者的空列表。