I edited it as you suggested but it is giving another error like 'method'
object is not subscriptable

On Wed, Apr 3, 2019 at 10:24 PM Nikolay Smirnov <nikolays...@gmail.com>
wrote:

> Your request.POST does not contain "search1".
> Do so search1 = request.POST.get('search1')
>
> Example:
> def viewstr(request):
>     views = create_store.objects.all()
>     brn = Prod_Brand.objects.all()
>     mi = ''
>     if request.method == 'POST':
>         search1 = request.POST.get('search1')
>         if search1:
>             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.get('search')
>         if search:
>             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})
>
>
>
>
>
> On Wednesday, 3 April 2019 13:33:20 UTC+2, Abhineet Baranwal wrote:
>>
>>
>> *this is my views file which creates 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})*
>>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at https://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/4a37bed9-2860-4a54-9ff4-f6f43efa12ce%40googlegroups.com
> <https://groups.google.com/d/msgid/django-users/4a37bed9-2860-4a54-9ff4-f6f43efa12ce%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAFOSuXLiCVsQy4VhbyzJgtxy5LYKKVqdm%2BWPhPXmrs9j9OCVSg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to