的Django = 1.3 蟒= 2.7 我收到此错误“列表索引超出范围”
Django Version: 1.3
Python Version: 2.7.6
Installed Applications:
['autoslug',
'tinymce',
'lfstheme',
'compressor',
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.staticfiles',
'django.contrib.sites',
'django.contrib.flatpages',
'django.contrib.redirects',
'django.contrib.sitemaps',
'django_countries',
'pagination',
'reviews',
'tagging',
'portlets',
'lfs',
'lfs.tests',
'lfs.core',
'lfs.caching',
'lfs.cart',
'lfs.catalog',
'lfs.checkout',
'lfs.criteria',
'lfs.customer',
'lfs.discounts',
'lfs.export',
'lfs.gross_price',
'lfs.integrationtests',
'lfs.mail',
'lfs.manage',
'lfs.marketing',
'lfs.manufacturer',
'lfs.net_price',
'lfs.order',
'lfs.page',
'lfs.payment',
'lfs.portlet',
'lfs.search',
'lfs.shipping',
'lfs.supplier',
'lfs.tagging',
'lfs.tax',
'lfs.customer_tax',
'lfs.utils',
'lfs.voucher',
'lfs_contact',
'lfs_order_numbers',
'postal',
'paypal.standard.ipn',
'paypal.standard.pdt',
'yoga',
'sutra',
'mail']
Installed Middleware:
('django.middleware.csrf.CsrfViewMiddleware',
'django.middleware.common.CommonMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'lfs.utils.middleware.RedirectFallbackMiddleware',
'pagination.middleware.PaginationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware')
django中的错误我正在
Traceback:
File "/home/gaurav/venv/local/lib/python2.7/site-packages/django/core/handlers/base.py" in get_response
111. response = callback(request, *callback_args, **callback_kwargs)
File "/home/gaurav/venv/local/lib/python2.7/site-packages/django/contrib/admin/sites.py" in wrapper
214. return self.admin_view(view, cacheable)(*args, **kwargs)
File "/home/gaurav/venv/local/lib/python2.7/site-packages/django/utils/decorators.py" in _wrapped_view
93. response = view_func(request, *args, **kwargs)
File "/home/gaurav/venv/local/lib/python2.7/site-packages/django/views/decorators/cache.py" in _wrapped_view_func
79. response = view_func(request, *args, **kwargs)
File "/home/gaurav/venv/local/lib/python2.7/site-packages/django/contrib/admin/sites.py" in inner
196. return self.login(request)
File "/home/gaurav/venv/local/lib/python2.7/site-packages/django/views/decorators/cache.py" in _wrapped_view_func
79. response = view_func(request, *args, **kwargs)
File "/home/gaurav/venv/local/lib/python2.7/site-packages/django/contrib/admin/sites.py" in login
331. return login(request, **defaults)
File "/home/gaurav/venv/local/lib/python2.7/site-packages/django/utils/decorators.py" in _wrapped_view
93. response = view_func(request, *args, **kwargs)
File "/home/gaurav/venv/local/lib/python2.7/site-packages/django/views/decorators/cache.py" in _wrapped_view_func
79. response = view_func(request, *args, **kwargs)
File "/home/gaurav/venv/local/lib/python2.7/site-packages/django/contrib/auth/views.py" in login
69. context_instance=RequestContext(request, current_app=current_app))
File "/home/gaurav/venv/local/lib/python2.7/site-packages/django/template/context.py" in __init__
177. self.update(processor(request))
File "/home/gaurav/venv/local/lib/python2.7/site-packages/lfs/core/context_processors.py" in main
10. shop = get_default_shop(request)
File "/home/gaurav/venv/local/lib/python2.7/site-packages/lfs/core/utils.py" in get_default_shop
60. shop = Shop.objects.all()[0]
File "/home/gaurav/venv/local/lib/python2.7/site-packages/django/db/models/query.py" in __getitem__
190. return list(qs)[0]
Exception Type: IndexError at /admin/
Exception Value: list index out of range
我为这个项目创建了虚拟环境并在那里安装了django1.3。 请帮我解决这个错误。
答案 0 :(得分:1)
让我们试着理解错误。根据回溯,错误发生在lfs/core/utils.py
的以下行:
shop = Shop.objects.all()[0]
您的数据库中没有商店,因此all()
方法返回一个空列表。因此错误,它试图获取空列表的第一个元素。
在能够使用此模块之前,您需要create at least one Shop
。
答案 1 :(得分:0)
添加上面的答案,特别是在返回数据值时,最好返回错误,或者在您的情况下,可能通过添加try / catch或任何其他机制来静默失败。
此外,在您安装的应用程序中,我认为您不需要添加所有内容,例如lfs就足够了。