【问题标题】:HTML Web.py Web framework Simple Category searchHTML Web.py Web 框架 简单类别搜索
【发布时间】: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">&#9654;</span>
        <ul class="subF1">
           <form action="" method="post">
             $:FilterForm.render()
           </form>
        </ul>
     </li>
 </ul>

【问题讨论】:

    标签: python html sqlite web.py web-frameworks


    【解决方案1】:

    所以这最终是一个错字,阅读手册页后,事情变得更加清晰。如果有人遇到类似的问题,我至少会发布有效的方法。模型

    型号:

    def filter_auctions(category, price_min, price_max):
        return db.select('Auction', where="Category=$category AND Price>$price_min 
        AND Price<$price_max", vars=locals())
    

    表格:

    if FilterForm.validates():
        Auctions = model.filter_auctions(FilterForm.d.Search,   FilterForm.d.Category, FilterForm.d.minPrice, 
        FilterForm.d.maxPrice)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-11-17
      • 1970-01-01
      • 1970-01-01
      • 2018-12-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多