下面的是在模块里面的输出
{# 加入检索逻辑 #}
<div style='margin-top: 30px;line-height: 30px;padding: 10px; '>
<form method="GET">
<input type="text" name="searchtitle"/> <input type="submit" value="提交检索"/>
</form>
</div>
这是后台逻辑
#接收参数 searchtitle 搜索商品名称
searchtitle = request.GET.get('searchtitle','')
#使用模糊查询 加入倒序逻辑 .reverse()
res = Product.objects.filter(name__contains = searchtitle).order_by('-price','-count')
当使用 Product.objects.filter(name__contains = searchtitle)查询时,在模板里一直显示的空白,后台打印也一直是空白。
经过长时间的查找,最后才找到根本就不是代码写错了emmm~~,
是因为数据库里面的字段设置有错误,这里的name字段应该utf8的形式