Python 在django搜索中没有得到结果,但个人搜索工作正常

Python 在django搜索中没有得到结果,但个人搜索工作正常,python,django,django-views,django-templates,django-queryset,Python,Django,Django Views,Django Templates,Django Queryset,我的问题是,当我向单个搜索字段添加简单功能时,它在单个搜索字段中运行良好,比如在为位置字段添加功能后,它按照我的要求运行,但在为另一个字段添加另一个功能后,它不显示任何内容,即使第一个字段也不显示结果,我认为这是一个非常愚蠢的问题,但我不明白,请帮助我的程序员!(我已经添加了html和views.py代码,如果您还需要什么,请告诉我guyz) html代码 <form action="{% url 'search-page' %}" method=""> &l

我的问题是,当我向单个搜索字段添加简单功能时,它在单个搜索字段中运行良好,比如在为位置字段添加功能后,它按照我的要求运行,但在为另一个字段添加另一个功能后,它不显示任何内容,即使第一个字段也不显示结果,我认为这是一个非常愚蠢的问题,但我不明白,请帮助我的程序员!(我已经添加了html和views.py代码,如果您还需要什么,请告诉我guyz)

html代码

<form action="{% url 'search-page' %}" method="">
            <div class="row">
                <div class="col-12 col-lg-10">
                    <div class="row">
                        <div class="col-12 col-md-6 col-lg-3">
                            <select name="location" id="location" class="form-control">
                                <option value="">Location</option>
                                {% for key,value in location_choices.items %}
                                <option value="{{ key }}">{{ value }}</option>
                                {% endfor %}

                            </select>
                        </div>
                        <div class="col-12 col-md-6 col-lg-3">
                            <select name="types" id="types" class="form-control">
                                <option value="all-types">All Types</option>
                                {% for key,value in property_choices.items %}
                                <option value="{{ key }}">{{ value }}</option>
                                {% endfor %}

                            </select>
                        </div>
                        <div class="col-12 col-md-6 col-lg-3">
                            <select name="city" id="city" class="form-control">
                                <option value="01">All City</option>
                                {% for key,value in city_choices.items %}
                                <option value="{{ key }}">{{ value }}</option>
                                {% endfor %}

                            </select>
                        </div>
                        <div class="col-12 col-md-6 col-lg-3">
                            <select name="status" id="all" class="form-control">
                                <option value="01">Status</option>
                                {% for key,value in status_choices.items %}
                                <option value="{{ key }}">{{ value }}</option>
                                {% endfor %}

                            </select>
                        </div>
                        <div class="col-12 col-md-6 col-lg-3">
                            <select name="bedroom" id="bedrooms" class="form-control">
                                <option value="">Bedrooms</option>
                                {% for key,value in bedroom_choices.items %}
                                <option value="{{ key }}">{{ value }}</option>
                                {% endfor %}

                            </select>
                        </div>
                        <div class="col-12 col-md-6 col-lg-3">
                            <select name="bathroom" id="bathroom" class="form-control">
                                <option value="Bathroom">Bathroom</option>
                                {% for key,value in bathroom_choices.items %}
                                <option value="{{ key }}">{{ value }}</option>
                                {% endfor %}

                            </select>
                        </div>
                        <div class="col-12 col-md-6 col-lg-3">
                            <select name="price" id="bathroom" class="form-control">
                                <option value="Bathroom">Price</option>
                                {% for key,value in price_choices.items %}
                                <option value="{{ key }}">{{ value }}</option>
                                {% endfor %}

                            </select>
                        </div>
                        <div class="col-12 col-md-6 col-lg-3">
                            <select name="size" id="bathroom" class="form-control">
                                <option value="Bathroom">Lot Size</option>
                                {% for key,value in lot_area_choices.items %}
                                <option value="{{ key }}">{{ value }}</option>
                                {% endfor %}

                            </select>
                        </div>
                        <!-- <div class="col-12 col-md-6 col-lg-3">
                            <div class="slider-range mb-15">
                                <div class="range-price text-white">Price [30000 - 150000]$</div>
                                <div class="slider-range-price ui-slider ui-slider-horizontal ui-widget ui-widget-content ui-corner-all"
                                    data-min="0" data-max="200000" data-unit="$" data-value-min="30000"
                                    data-value-max="150000" data-label-result="Price">
                                    <div class="ui-slider-range ui-widget-header ui-corner-all"></div>
                                    <span class="ui-slider-handle ui-state-default ui-corner-all"
                                        tabindex="0"></span>
                                    <span class="ui-slider-handle ui-state-default ui-corner-all"
                                        tabindex="0"></span>
                                </div>
                            </div>
                        </div> -->
                        <!-- <div class="col-12 col-md-6 col-lg-3">
                            <div class="slider-range mb-15">
                                <div class="range-size text-white">Size [9762 - 72063]sqFt</div>
                                <div data-min="0" data-max="98623" data-unit="sqFt"
                                    class="slider-range-size ui-slider ui-slider-horizontal ui-widget ui-widget-content ui-corner-all"
                                    data-value-min="9762" data-value-max="72063" data-label-result="Size">
                                    <div class="ui-slider-range ui-widget-header ui-corner-all"></div>
                                    <span class="ui-slider-handle ui-state-default ui-corner-all"
                                        tabindex="0"></span>
                                    <span class="ui-slider-handle ui-state-default ui-corner-all"
                                        tabindex="0"></span>
                                </div>
                            </div>
                        </div> -->
                    </div>
                </div>
                <div class="col-12 col-lg-2">
                    <button type="submit" class="btn rehomes-search-btn">Search</button>
                </div>
            </div>
        </form>

如果没有显示字段或结果,它会显示什么?您能确定模板中的哪一点失败吗?您还可以安装django调试工具栏,查看呈现模板时模板的上下文。实际上,它没有显示结果,正如您可以看到的,有3个不同搜索字段的功能,如果我注释掉2个字段中的任何一个功能,那么它就可以正常工作,主要的是,如果我只为单个字段添加搜索功能,它会工作,但当我为另一个字段添加相同的功能时,它不会显示结果,即使第一个字段显示结果,但在添加另一个1后,它也不会显示结果,但所有字段的功能都是相同的,你觉得怎么样?我会安装Django调试工具栏并检查发送到模板的上下文。如果没有显示字段或结果,它会显示什么?您能确定模板中的哪一点失败吗?您还可以安装django调试工具栏,查看呈现模板时模板的上下文。实际上,它没有显示结果,正如您可以看到的,有3个不同搜索字段的功能,如果我注释掉2个字段中的任何一个功能,那么它就可以正常工作,主要的是,如果我只为单个字段添加搜索功能,它会工作,但当我为另一个字段添加相同的功能时,它不会显示结果,即使第一个字段显示结果,但在添加另一个1后,它也不会显示结果,但所有字段的功能都是相同的,你觉得怎么样?我会安装Django调试工具栏并检查发送到模板的上下文。
def search(request):
property_list = Property.objects.order_by('-date_added')

# Search_location
if 'location' in request.GET:
    location = request.GET['location']
    if location:
        property_list = property_list.filter(state__iexact=location)

# Search_types
if 'types' in request.GET:
    types = request.GET['types']
    if types:
        property_list = property_list.filter(property_types__iexact=types)

# Search_status
if 'bedroom' in request.GET:
    bedroom = request.GET['bedroom']
    if bedroom:
        property_list = property_list.filter(bedroom__lte=bedroom)

context = {
    'property_data': property_list,
    'location_choices': choices.location_choices,
    'property_choices': choices.property_choices,
    'city_choices': choices.city_choices,
    'status_choices': choices.status_choices,
    'bedroom_choices': choices.bedroom_choices,
    'bathroom_choices': choices.bathroom_choices,
    'price_choices': choices.price_choices,
    'lot_area_choices': choices.lot_area_choices
}
return render(request, 'property/search.html', context)
if 'location' in request.GET:
    location = request.GET['location']
    if location:
        property_list = property_list.filter(state__iexact=location)

# Search_types
if 'types' in request.GET:
    types = request.GET['types']
    if types:
        property_list = property_list.filter(property_types__iexact=types)

# Search_status
if 'bedroom' in request.GET:
    bedroom = request.GET['bedroom']
    if bedroom:
        property_list = property_list.filter(bedroom__lte=bedroom)