2016-04-30 67 views
0

我是初学者,我无法理解为什么会出现这个错误。从几个帖子尝试很多东西: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但结果为零。Django:ValueError在/ books/search /需要超过1个值才能解压

文件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.' 

错误:

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

任何想法?请帮助

+0

'searc.query(message,'qi')'这会返回什么? – AKS

+0

Whta是“搜索者”? “searc.query”返回什么? –

+0

搜索者正在从数据库中获取数据,并做了一切正确 – user3508182

回答

0

从您的代码片段中查询方法返回HttpResponse(如果for循环执行)或None。它们都不像您在搜索视图中期望的那样是2个元素的元组。检查你的查询方法,并返回一个正确的结果,很可能你想从我看到的元组列表(分数,网址)。

相关问题