2013-04-17 62 views
0

models.pyAppEngine上查詢

from django.db import models 
from google.appengine.ext import db 

class ligas(models.Model): 
    llave = models.TextField() 
    liga = models.TextField() 

views.py

from django.http import Http404, HttpResponse 
from google.appengine.ext import db 
from models import ligas 

def liga(request, offset): 
    dt = get_url(offset) 
    html = "<html><body>la liga para %s es %s</body></html>" % (offset, dt) 
    return HttpResponse(html) 

def get_url(valor): 
    direc = '' 
    q = ligas.objects.all() 
    q.filter("llave=", valor) 
    direc = q.get() 
    return direc.liga 

我是新使用Django與谷歌應用程序引擎。我不能查詢數據庫。即時得到這個錯誤:

Exception Type: ValueError 
Exception Value: too many values to unpack 

在外殼直接進行查詢,我得到這樣的:

>>> uno = ligas.objects.all()[0] 
>>> uno.liga 
u'www.yahoo.com' 
>>> uno.llave 
u'yahoo' 

我不能找出我拿錯。 請任何幫助。

traceback: 
Environment: 


Request Method: GET 
Request URL: http://localhost:8080/sake/as/ 

Django Version: 1.3.7 
Python Version: 2.7.2 
Installed Applications: 
['django.contrib.admin', 
'django.contrib.contenttypes', 
'django.contrib.auth', 
'django.contrib.sessions', 
'djangotoolbox', 
'autoload', 
'dbindexer', 
'polls', 
'djangoappengine'] 
Installed Middleware: 
('autoload.middleware.AutoloadMiddleware', 
'django.middleware.common.CommonMiddleware', 
'django.contrib.sessions.middleware.SessionMiddleware', 
'django.contrib.auth.middleware.AuthenticationMiddleware') 

回溯:

File "/Users/alex_gmoca/kl-panel/django/core/handlers/base.py" in get_response 
    111.       response = callback(request, *callback_args, **callback_kwargs) 
File "/Users/alex_gmoca/kl-panel/sake/views.py" in liga 
    6.  dt = get_url(offset) 
File "/Users/alex_gmoca/kl-panel/sake/views.py" in get_url 
    13. q.filter("llave=", "as") 
File "/Users/alex_gmoca/kl-panel/django/db/models/query.py" in filter 
    552.   return self._filter_or_exclude(False, *args, **kwargs) 
File "/Users/alex_gmoca/kl-panel/django/db/models/query.py" in _filter_or_exclude 
    570.    clone.query.add_q(Q(*args, **kwargs)) 
File "/Users/alex_gmoca/kl-panel/django/db/models/sql/query.py" in add_q 
    1192.        can_reuse=used_aliases, force_having=force_having) 
File "/Users/alex_gmoca/kl-panel/django/db/models/sql/query.py" in add_filter 
    1022.   arg, value = filter_expr 

Exception Type: ValueError at /sake/as/ 
Exception Value: too many values to unpack 
+0

您好,歡迎您發表全部回溯,不僅僅是最後一行。這將幫助其他人幫助你! –

+0

你使用雲端SQL嗎? – singer

回答

1

q.filter("llave=", valor) 

應該

q.filter(llave=valor) 

更多信息,請參見the docs