0

我尝试实现过滤功能以使用发布表单从选择标签中获取数据,但结果始终为无

视图.py

def filter(request):
    products = Product.objects.all()
    if request.method == 'POST':
      title = request.POST.get('da',None)
      print(title)
      titre = Product.objects.filter(title=title)
      print(titre)
      return render(request, 'searchapp/searchview.html', {'qs': titre})

    else:
     return render(request,'searchapp/searchview.html',{'qs':products})

html:

div>
    <form action="{% url 'search:query' %}" method="post" enctype="multipart/form-data">
      {% csrf_token %}
            <div class="form-group">
                <label>Title</label>
                  <select title="da" class="form-control">
                        {% for obj in qs %}
                 <option value="{{obj}}">{{obj}}</option>
                         {%endfor%}
                         </select>
            </div>
            <button type="submit" class="btn btn-warning btn-lg">Add Product</button>
        </form>
</div>

4

1 回答 1

0

在您的选择中使用 name='da' 而不是 title 属性。

于 2020-03-06T18:48:27.130 回答