【发布时间】:2016-04-28 02:46:38
【问题描述】:
我正在尝试为类别创建搜索过滤器。除其他外,问题在于 python 选择如何无法按照我的心理意愿工作。在 SQLite 中,我想要 SELECT * FROM Auctions WHERE Category='arg'。当我输入 arg 所在的玩具时,这适用于数据库。 我在下拉列表中有类别,但不确定如何提取值。如果使用搜索表单,我希望它只显示现在选择的类别,然后将在价格字段上工作。我只是想弄清楚 web.py 的方式来做到这一点。这就是我所拥有的。这是一个学校项目。
表格:
FilterForm = web.form.Form(
web.form.Textbox('Search', web.form.notnull, description="Search:"),
web.form.Dropdown(name='Category', args=[]),
web.form.Textbox('minPrice', web.form.notnull, description="Price Min: "),
web.form.Textbox('maxPrice', web.form.notnull, description="Price Max: ")
web.form.Button('Apply Search Filter')
)
def POST(self):
if not FilterForm.validates():
Auctions = model.filter_auctions(FilterForm.d.Category, FilterForm.d.maxPrice, FilterForm.d.minPrice)
FilterForm.Category.args = [(a.ItemID, a.Category) for a in Auctions]
return render.index(Auctions,
AuctionForm,
Bids,
BidForm,
Logins,
LoginForm,
FilterForm,
TimeForm)
raise web.seeother('/')
型号:
def filter_auctions(category, price_min, price_max):
return db.select('Auction', where="Category=category")
HTML:
<ul id="filtermenu">
<li><a href="#">Add Filter</a><span class="rarrow">▶</span>
<ul class="subF1">
<form action="" method="post">
$:FilterForm.render()
</form>
</ul>
</li>
</ul>
【问题讨论】:
标签: python html sqlite web.py web-frameworks