사용자가 검색 버튼을 누르면 검색 필드가 비어 있으며 페이지의 모든 기사를 가져옵니다. 암호:
class SearchResultsView(ArticlesView):
def get_queryset(self, request):
if request.POST.has_key('search'):
return self.model.objects.filter(
Q(title__icontains=request.POST['search']) |
Q(content__icontains=request.POST['search'])
).distinct()
return []
도와주세요.
가져 오기 search
매개 변수를이 비어인지 아닌지 확인 :
search = request.POST.get('search')
if search:
return self.model.objects.filter(
Q(title__icontains=search) |
Q(content__icontains=search)
).distinct()
get()
None
검색이 제공되지 않으면 반환 됩니다. search
빈 문자열로 전달 되면 if search
빈 문자열은 정의에 따라 거짓이므로 조건이 충족되지 않습니다.
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다