Search matches 250 users
meld/components/search.py
from flask_meld import Component from app.models import User class Search(Component): search = "" @property def users(self): return User.query.filter(User.name.contains(self.search)).all()
templates/meld/search.html
<div> <h1>Search for a user in a database</h1> <input meld:model="search" type="text" placeholder="Search for name"> <p>Search matches <span class="underline">{{users|length}}</span> users</p> <ul class="grid"> {% for user in users %} <li class="card"> <h3>{{ user.name }}</h3> </li> {% endfor %} </ul> </div> <!--Include {% meld 'search' %} anywhere in your template to add the component --!>