Django-如果object_list ==空则无法显示图像

时间:2019-01-21 12:49:39

标签: python django templates

如果我的searchg函数找不到任何内容,我想显示图像。 我设置了2个搜索功能。一个用于elasticsearch,另一个用于本地搜索查询视图,无论如何,如果object_list为空,那么一个用于elasticsearch似乎不起作用或至少不显示“未找到”图像?

elastic_search_function:

 var second = new MyType[] {A, B}; // or whatever IEnumerable<MyType>

 ...

 // Items to exclude
 HashSet<MyType> exclude = new HashSet<MyType>(second, new CustomComparer());

 var result = first // {A, B, C, D, E}
   .Where(item => !exclude.Contains(item)) // all items but appear in exclude - i.e. second
   .ToList();

template.html

def globalsearch_elastic(request):
    qs = request.GET.get('qs')
    page = request.GET.get('page')
    if qs:
        qs = PostDocument.search().query("multi_match", query=qs, fields=["title", "content", "tag"])
        qs = qs.to_queryset()
    else:
        qs = ''
    paginator = Paginator(qs, 10)  # Show 10 results per page
    try:
        qs = paginator.page(page)
    except PageNotAnInteger:
        qs = paginator.page(1)
    except EmptyPage:
        qs = paginator.page(paginator.num_pages)
    return render(request, 'myproject/search/search_results_elastic.html', {'object_list':qs})

1 个答案:

答案 0 :(得分:1)

如何使用empty这样:

#works
command = './grid < /home/felipe/Documents/proteins/grid.in'.split(' ')

os.system(command)