【发布时间】:2014-06-01 16:37:50
【问题描述】:
我收到此错误:
DoesNotExist at /admin
Quiz matching query does not exist. Lookup parameters were {'url': u'admin'}
但是,我已经检查了 SO 中的其他 solution,关于删除 #'django.contrib.sites',这对我不起作用。
这些是我安装的应用程序:
INSTALLED_APPS = (
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
#'django.contrib.sites',
'django.contrib.messages',
'django.contrib.staticfiles',
'simulado',
'multichoice',
'django.contrib.admin',
)
这是我的 urls.py
from django.conf.urls import patterns, include, url
# Uncomment the next two lines to enable the admin:
from django.contrib import admin
admin.autodiscover()
urlpatterns = patterns('',
# Examples:
# url(r'^$', 'quiz.views.home', name='home'),
# url(r'^quiz/', include('quiz.foo.urls')),
# Uncomment the next line to enable the admin:
url(r'^admin/', include(admin.site.urls)),
####################
# quiz base url
url(r'^$', 'simulado.views.index'),
# quiz category list
url(r'^category/(?P<slug>[^\.]+)', 'simulado.views.view_category', name='view_quiz_category'),
# cart
#url(r'^carrinho$', 'simulado.views.carrinho'),
#url(r'^carrinho2$', 'simulado.views.carrinho2', name = "carrinho2"),
#url(r'^buyItem$', 'simulado.views.buyItem', name = "buyItem"),
# progress
url(r'^progress/$', 'simulado.views.progress'),
url(r'^progress$', 'simulado.views.progress'),
# passes variable 'quiz_name' to quiz_take view
url(r'^(?P<quiz_name>[\w-]+)/$',
'simulado.views.quiz_take'), # quiz/
url(r'^(?P<quiz_name>[\w-]+)$',
'simulado.views.quiz_take'), # quiz
url(r'^(?P<quiz_name>[\w-]+)/take/$',
'simulado.views.quiz_take'), # quiz/take/
url(r'^(?P<quiz_name>[\w-]+)take$',
'simulado.views.quiz_take'), # quiz/take
)
这是我的同步数据库的结果
Creating tables ...
Creating table auth_permission
Creating table auth_group_permissions
Creating table auth_group
Creating table auth_user_groups
Creating table auth_user_user_permissions
Creating table auth_user
Creating table django_content_type
Creating table django_session
Creating table simulado_category
Creating table simulado_quiz
Creating table simulado_progress
Creating table simulado_sitting
Creating table multichoice_question_quiz
Creating table multichoice_question
Creating table multichoice_answer
Creating table django_admin_log
You just installed Django's auth system, which means you don't have any superusers defined.
admin.autodiscover()
You just installed Django's auth system, which means you don't have any superusers defined.
Would you like to create one now? (yes/no): yes
Username (leave blank to use 'filipeferminiano'):
Email address: filipe.ferminiano@gmail.com
Password:
Password (again):
Superuser created successfully.
这是回溯
Environment:
Request Method: GET
Request URL: http://127.0.0.1:8000/admin
Django Version: 1.5
Python Version: 2.7.6
Installed Applications:
('django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'simulado',
'multichoice',
'django.contrib.admin')
Installed Middleware:
('django.middleware.common.CommonMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware')
Traceback:
File "/usr/local/Cellar/python/2.7.6/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/core/handlers/base.py" in get_response
115. response = callback(request, *callback_args, **callback_kwargs)
File "/Users/filipeferminiano/Documents/django/quiz/quiz/simulado/views.py" in quiz_take
71. quiz = Quiz.objects.get(url=quiz_name.lower())
File "/usr/local/Cellar/python/2.7.6/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/db/models/manager.py" in get
143. return self.get_query_set().get(*args, **kwargs)
File "/usr/local/Cellar/python/2.7.6/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/db/models/query.py" in get
401. (self.model._meta.object_name, kwargs))
Exception Type: DoesNotExist at /admin
Exception Value: Quiz matching query does not exist. Lookup parameters were {'url': u'admin'}
然后 django 创建一个没有显示任何错误的超级用户。 我该怎么办?
【问题讨论】:
-
你能提供整个堆栈跟踪而不是你的解释版本吗? :) 此外,您的 urls.py 是“释义”。当涉及到代码时,包含实际代码很有帮助。最后,请附上您提到的“其他解决方案”的链接。尽管有很多可能性,但这里没有足够的细节来知道出了什么问题。
-
我更新了代码。看看
-
当您尝试在浏览器中导航到 localhost:8000/admin 时,您会收到此堆栈跟踪信息? DoesNotExist 向我建议它正在查询数据库中的模型(测验)并获得一个空集。管理页面很好地处理了这种情况,因为它很常见,所以我不确定你为什么会根据你提供的信息看到它。也许其他人会发现问题,但我认为最好的办法是发布或查看实际错误发生的堆栈跟踪的详细部分(逐行部分)。
-
供参考,这是DoesNotExist的官方文档。很简单。希望它能给你一个想法。我会首先检查您的测验模型并确保它没问题,然后可能会删除并重新同步您的数据库(因为您刚刚创建它,这是您的奢侈品),然后重新启动您的服务器。还要查看 admin.py 并确保您没有尝试显示不存在的模型。 docs.djangoproject.com/en/dev/ref/exceptions/…
-
@Andy 堆栈是什么意思?我想我误解了你。我现在粘贴所有的回溯。