0

I am trying to fetch specific rows from table on the basis of user input in forms. on pressing submit button, getting the following error.

Error:

DoesNotExist at /search/ Dinucleotides matching query does not exist. Request Method: POST Request URL: http://127.0.0.1:8000/search/ Django Version: 4.0.6 Exception Type: DoesNotExist Exception Value:
Dinucleotides matching query does not exist. Exception Location: C:\ssrdb\lib\site-packages\django\db\models\query.py, line 496, in get Python Executable: C:\ssrdb\Scripts\python.exe Python Version: 3.10.5 Python Path: ['C:\ssrdb\Scripts\chick', 'C:\python310.zip', 'C:\DLLs', 'C:\lib', 'C:\', 'C:\ssrdb', 'C:\ssrdb\lib\site-packages'] Server time: Wed, 14 Sep 2022 07:08:27 +0000

views.py

from django.shortcuts import render
from django.views.generic import TemplateView, ListView, DetailView
from ssr.models import Dinucleotides
from ssr.forms import InputForm



# Create your views here.
def homepage(request):
    return render(request,'index.html')

def searchpage(request):
  if(request.method == 'GET'):
    form=InputForm()
    return render(request,'search.html',{'form':form})
 
  else:
    print(request.POST)
    if(request.POST['Motiff']):
       obj1=Dinucleotides.objects.get(SSRtype='Motiff')
       return render(request,'result.html',{'obj1':obj1})
shaik moeed
  • 5,300
  • 1
  • 18
  • 54
  • Check similar question [matching query does not exist Error in Django](https://stackoverflow.com/a/5508924/8353711) on SO – shaik moeed Sep 14 '22 at 07:26
  • Looks like you don't want to get an Dinucleotides object with SSRtype 'Motiff", but with the value of POST['Motiff']? It's a big assumption from my side, but can you try to change the `objects.get` statement into `obj1=Dinucleotides.objects.get(SSRtype=request.POST['Motiff'])` – JerkMan Sep 14 '22 at 08:56

1 Answers1

0

first of all, pass data in function and then call query.