0
我有我的連接Django的觀點與我的Django的模板的麻煩。我想用FormMixin和ListView來使用基於類的視圖。Django的類視圖與FormMixin和ListView
class Merchants(FormMixin, ListView):
"""
A view of that shows a list of all the merchants.
"""
template_name = "reporting/merchants.html"
model = models.Merchant
context_object_name = "merchants"
def get_queryset(self):
queryset = super(ViewClassName, self).get_queryset()
search_query = self.request.GET.get("q", None)
if search_query:
queryset = queryset.filter(name__ilike=search_query)
return queryset
我的目標是用我的get_queryset功能在我的模板,讓用戶搜索商家。這種形式發佈給自己,但不幸的是它沒有返回任何東西。我讀過FormMixins上的Django文檔,但仍然無法弄清楚。任何幫助將不勝感激。
<form action= "">
<input name="q" placeholder="search for merchant">
<button type="submit">Search </button>
</form>
謝謝!
'FormMixin'這裏沒有做任何事情,可以拆卸。 –