0

I am beginner and i am unable to understand why this error is coming. Tries lots of things from several posts: Django forms: need more than 1 value to unpack , ValueError: need more than 1 value to unpack , Python - ValueError: need more than 1 value to unpack , ValueError: need more than 1 value to unpack, django email error but result is zero.

file views.py

def query(self,q, type = None):
        #q="python"
        rows, wordids = self.getmatchrows(q) #q=python
        scores = self.getscoredlist(rows, wordids, type)
        rankedscores = sorted([(score, url) for (url, score) in scores.items()],reverse = 1)
        #print the first 20 results on the screen

        for (score, urlid) in rankedscores[0:20]:
            t= self.textcomplexity(urlid)
            print '%f\t%s' %(score, self.geturlname(urlid))
            return HttpResponse(t)      

def search_form(request):
    return render(request, 'books/index.html')

def search(request):
    global message
    if 'q' in request.GET:
        message = request.GET['q']
        searc=searcher("db.sqlite3")
        wordids,urls=searc.query(message,'qi') # error pointing here

    else:
        message = 'You submitted an empty form.'

Error:

ValueError at /books/search/ need more than 1 value to unpack at wordids,urls=searc.query(message,'qi')

Any idea?? Please help

Community
  • 1
  • 1
user3508182
  • 457
  • 1
  • 4
  • 13

1 Answers1

0

From your code snippet the query method returns an HttpResponse (if the for loop executes) or None. Both of them are not a tuple of 2 elements as you expect in the search view. Review your query method and return a proper result, most likely you want a list of tuples (score, url) from what I see.

Gabriel Muj
  • 3,682
  • 1
  • 19
  • 28