django

13 views
Skip to first unread message

Abhineet Baranwal

unread,
Apr 3, 2019, 7:33:20 AM4/3/19
to Django users
The below code works fine on one search but for another it gives an error like django.utils.datastructures.MultiValueDictKeyError: 'search1' . Can anyone tell me where i go wrong?




def viewstr(request):
    views = create_store.objects.all()
    brn = Prod_Brand.objects.all()
    mi = ''
    if request.method == 'POST':
        # mi = ''
        search1 = request.POST['search1']
        if search1 == '' :
            pass
        else:
            mi = create_store.objects.filter(Q(select_brand__Brand__icontains=search1))
            if mi:
                return render(request,'viewstr.html',{'vi':mi,'brn':brn})
        search = request.POST['search']
        if search == '' :
            pass
        else :
            mi = create_store.objects.filter(Q(id__icontains=search))
            if mi:
                return render(request,'viewstr.html',{'vi':mi,'brn':brn})

    return render(request,'viewstr.html',{'viewstr':viewstr,'vi':mi,'brn':brn})
Reply all
Reply to author
Forward
0 new messages