我只是在学习django,好吧,django对我来说最大的问题是,如果出现问题,我会得到一个巨大的追溯,没有任何信息真的出错了。
我实际上正在遵循此Tutorial中的教程步骤。 有没有解释如何阅读和理解django错误消息?
示例:
DoesNotExist at /admin/
Site matching query does not exist.
Request Method: GET
Request URL: http://localhost:8080/admin/
Django Version: 1.4.5
Exception Type: DoesNotExist
Exception Value:
Site matching query does not exist.
Exception Location: /usr/lib/python2.7/dist-packages/django/db/models/query.py in get, line 366
Python Executable: /usr/bin/python
Python Version: 2.7.3
Python Path:
['/home/ps/src/python/django',
'/usr/lib/python2.7',
'/usr/lib/python2.7/plat-linux2',
'/usr/lib/python2.7/lib-tk',
'/usr/lib/python2.7/lib-old',
'/usr/lib/python2.7/lib-dynload',
'/usr/local/lib/python2.7/dist-packages',
'/usr/lib/python2.7/dist-packages',
'/usr/lib/python2.7/dist-packages/PIL',
'/usr/lib/pymodules/python2.7/gtk-2.0',
'/usr/lib/python2.7/dist-packages/gst-0.10',
'/usr/lib/python2.7/dist-packages/gtk-2.0',
'/usr/lib/pymodules/python2.7']
Server time: So, 27 Okt 2013 19:32:52 +0100
Traceback:
File "/usr/lib/python2.7/dist-packages/django/core/handlers/base.py" in get_response
111. response = callback(request, *callback_args, **callback_kwargs)
File "/usr/lib/python2.7/dist-packages/django/contrib/admin/sites.py" in wrapper
213. return self.admin_view(view, cacheable)(*args, **kwargs)
File "/usr/lib/python2.7/dist-packages/django/utils/decorators.py" in _wrapped_view
91. response = view_func(request, *args, **kwargs)
File "/usr/lib/python2.7/dist-packages/django/views/decorators/cache.py" in _wrapped_view_func
89. response = view_func(request, *args, **kwargs)
File "/usr/lib/python2.7/dist-packages/django/contrib/admin/sites.py" in inner
195. return self.login(request)
File "/usr/lib/python2.7/dist-packages/django/views/decorators/cache.py" in _wrapped_view_func
89. response = view_func(request, *args, **kwargs)
File "/usr/lib/python2.7/dist-packages/django/contrib/admin/sites.py" in login
326. return login(request, **defaults)
File "/usr/lib/python2.7/dist-packages/django/views/decorators/debug.py" in sensitive_post_parameters_wrapper
69. return view(request, *args, **kwargs)
File "/usr/lib/python2.7/dist-packages/django/utils/decorators.py" in _wrapped_view
91. response = view_func(request, *args, **kwargs)
File "/usr/lib/python2.7/dist-packages/django/views/decorators/cache.py" in _wrapped_view_func
89. response = view_func(request, *args, **kwargs)
File "/usr/lib/python2.7/dist-packages/django/contrib/auth/views.py" in login
53. current_site = get_current_site(request)
File "/usr/lib/python2.7/dist-packages/django/contrib/sites/models.py" in get_current_site
92. current_site = Site.objects.get_current()
File "/usr/lib/python2.7/dist-packages/django/contrib/sites/models.py" in get_current
25. current_site = self.get(pk=sid)
File "/usr/lib/python2.7/dist-packages/django/db/models/manager.py" in get
131. return self.get_query_set().get(*args, **kwargs)
File "/usr/lib/python2.7/dist-packages/django/db/models/query.py" in get
366. % self.model._meta.object_name)
Exception Type: DoesNotExist at /admin/
Exception Value: Site matching query does not exist.
这件事要告诉我什么事? “/ admin /”的“DoesNotExist”是什么?关于“DoesNotExists”的描述仅说明:“一个对象不存在”。
管理界面之前肯定有用,但我刚刚在我的模型中玩我的应用程序,但即使从我的项目中从settings.py中删除我的应用程序INSTALLED_APPS后,我也会收到该消息。 我的应用程序本身似乎有效,但管理界面却没有。
现在,谷歌搜索我的问题后,我发现我必须注释掉“django.contrib.sites”,之后一切正常。但我不相信这会是django的方式:每次如果发生错误,去google,传递令人困惑的消息并通过try-error查找哪些答案将与我的问题相符。
我想真正理解什么是django / python告诉什么是“真正”的问题,而不仅仅是“django深处某处的错误17”。
任何想法如何“阅读”此错误消息?
答案 0 :(得分:2)
您应该将DEBUG设置为True。然后,您将获得更多信息性错误消息,并在回溯中的每个点处完成代码上下文和局部变量。
在您的情况下,您在Site表(来自django.contrib.sites)中缺少一个条目,该条目应该在您运行manage.py syncdb
时创建。