好吧,所以我试图允许用户在我使用sqlalchemy设置的数据库中搜索电影/电视节目。我跟着一个教程,能够使用以下代码从我的数据库中将所有电影打印到屏幕上:
<div class="row">
<div class="col-sm-4 portfolio-item">
{% for movie in movies %}
<h2 class="post-title">{{ movie.title }}</h2>
<p>{{ movie.description }}</p>
{% endfor %}
</div>
</div>
但是,当我尝试添加搜索功能时,什么都不会出现。当我进行搜索时,我得到了这个结果:
SELECT "movieTV".id AS "movieTV_id", "movieTV".title AS
"movieTV_title", "movieTV"."releaseDate" AS "movieTV_releaseDate",
"movieTV".producer AS "movieTV_producer", "movieTV".description AS
"movieTV_description", "movieTV".genre AS "movieTV_genre"
FROM "movieTV"
WHERE null
这是我的搜索功能:
@app.route('/', methods=['GET', 'POST'])
def index():
movies = MovieTV.query.all()
error = None
return render_template('index.html', error=error, movies=movies)
@app.route('/search')
def search():
movies = MovieTV.query.whoosh_search(request.args.get('query'))
return render_template('index.html', movies=movies)