DoesNotExist at / admin

时间:2014-06-01 16:37:51

标签: python django

我收到此错误:

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

)

这是我的syncdb

的结果
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创建一个没有显示任何错误的超级用户。 我该怎么办?

1 个答案:

答案 0 :(得分:1)

我发现了问题。

您正试图在最后没有斜杠的情况下获取localhost:8000/admin,并且 urls.py 中的网址与之匹配:

url(r'^(?P<quiz_name>[\w-]+)$',
    'simulado.views.quiz_take'),  #  quiz

在该视图中引发异常,它与管理员无关。修复您的网址以及所有网址。