models.py
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
直接在shell中进行查询我得到了这个:
>>> 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