擅长:python、mysql、java
<p>每个列都有<code>like()</code>方法,可以在<code>query.filter()</code>中使用。给定一个搜索字符串,在任意一侧添加一个<code>%</code>字符,以在两个方向上作为子字符串进行搜索。</p>
<pre><code>tag = request.form["tag"]
search = "%{}%".format(tag)
posts = Post.query.filter(Post.tags.like(search)).all()
</code></pre>