
正文
django-Q模块实现查询
提示:扫一扫查出行【扫一扫了解最新限行尾号】
复制提示
django Q模块
from django.db.models import Qdef search(request):
q = request.GET.get('q')
if q: # 查询字段不能为None,否者报错
# title或者content中包含了搜索的关键字
newses = News.objects.filter(Q(title__icontains=q)|Q(content__icontains=q))
context = {
'newses': newses
}
else:
context = {}
return render(request,'news/search.html',context=context)
更多的查询方法: http://www.cnblogs.com/tangpg/p/9010610.html







