修改django-userena settings.py
时遇到此错误
Environment:
Request Method: GET
Request URL: http://127.0.0.1:8000/admin/
Django Version: 1.3.1
Python Version: 2.7.2
Installed Applications:
['django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.messages',
'django.contrib.admin',
'easy_thumbnails',
'guardian',
'south',
'userena',
'userena.contrib.umessages',
'demo_project.profiles']
Installed Middleware:
('django.middleware.common.CommonMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.locale.LocaleMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'userena.middleware.UserenaLocaleMiddleware')
Traceback:
File "/home/elie/.django-projects/userena-demo/local/lib/python2.7/site-packages/django/core/handlers/base.py" in get_response
111. response = callback(request, *callback_args, **callback_kwargs)
File "/home/elie/.django-projects/userena-demo/local/lib/python2.7/site-packages/django/contrib/admin/sites.py" in wrapper
214. return self.admin_view(view, cacheable)(*args, **kwargs)
File "/home/elie/.django-projects/userena-demo/local/lib/python2.7/site-packages/django/utils/decorators.py" in _wrapped_view
93. response = view_func(request, *args, **kwargs)
File "/home/elie/.django-projects/userena-demo/local/lib/python2.7/site-packages/django/views/decorators/cache.py" in _wrapped_view_func
79. response = view_func(request, *args, **kwargs)
File "/home/elie/.django-projects/userena-demo/local/lib/python2.7/site-packages/django/contrib/admin/sites.py" in inner
196. return self.login(request)
File "/home/elie/.django-projects/userena-demo/local/lib/python2.7/site-packages/django/views/decorators/cache.py" in _wrapped_view_func
79. response = view_func(request, *args, **kwargs)
File "/home/elie/.django-projects/userena-demo/local/lib/python2.7/site-packages/django/contrib/admin/sites.py" in login
331. return login(request, **defaults)
File "/home/elie/.django-projects/userena-demo/local/lib/python2.7/site-packages/django/utils/decorators.py" in _wrapped_view
93. response = view_func(request, *args, **kwargs)
File "/home/elie/.django-projects/userena-demo/local/lib/python2.7/site-packages/django/views/decorators/cache.py" in _wrapped_view_func
79. response = view_func(request, *args, **kwargs)
File "/home/elie/.django-projects/userena-demo/local/lib/python2.7/site-packages/django/contrib/auth/views.py" in login
59. current_site = get_current_site(request)
File "/home/elie/.django-projects/userena-demo/local/lib/python2.7/site-packages/django/contrib/sites/models.py" in get_current_site
92. current_site = Site.objects.get_current()
File "/home/elie/.django-projects/userena-demo/local/lib/python2.7/site-packages/django/contrib/sites/models.py" in get_current
25. current_site = self.get(pk=sid)
File "/home/elie/.django-projects/userena-demo/local/lib/python2.7/site-packages/django/db/models/manager.py" in get
132. return self.get_query_set().get(*args, **kwargs)
File "/home/elie/.django-projects/userena-demo/local/lib/python2.7/site-packages/django/db/models/query.py" in get
349. % self.model._meta.object_name)
Exception Type: DoesNotExist at /admin/
Exception Value: Site matching query does not exist.
你知道造成这个错误的原因吗?
修改
关注哈克哈姆斯顿说明Site.objects.get(pk=settings.SITE_ID)
返回此错误
Traceback (most recent call last):
File "<console>", line 1, in <module>
File "/home/elie/.django-projects/userena-demo/local/lib/python2.7/site-packages/django/db/models/manager.py", line 132, in get
return self.get_query_set().get(*args, **kwargs)
File "/home/elie/.django-projects/userena-demo/local/lib/python2.7/site-packages/django/db/models/query.py", line 349, in get
% self.model._meta.object_name)
DoesNotExist: Site matching query does not exist.
>>> Site.objects.get(pk=settings.SITE_ID)
Traceback (most recent call last):
File "<console>", line 1, in <module>
File "/home/elie/.django-projects/userena-demo/local/lib/python2.7/site-packages/django/db/models/manager.py", line 132, in get
return self.get_query_set().get(*args, **kwargs)
File "/home/elie/.django-projects/userena-demo/local/lib/python2.7/site-packages/django/db/models/query.py", line 349, in get
% self.model._meta.object_name)
DoesNotExist: Site matching query does not exist.
在我的数据库中有一个site_id http://127.0.0.1:8000/' which is the domain name that i used instead of
example.com`
答案 0 :(得分:3)
您的SITE_ID
设置值可能与Site
对象的主键不对应。您可以通过运行以下方式进行验证:
$ ./manage.py shell
Python 2.7.1 [...]
>>> from django.contrib.sites.models import Site
>>> from django.conf import settings
>>> Site.objects.get(pk=settings.SITE_ID)
<Site: example.com>
如果最终命令的响应不是Site
对象(它可能会引发Site.DoesNotExist
异常),那就是问题所在。您可以通过不设置SITE_ID
来解决此问题,如果您不使用django.contrib.sites则不需要这样做。
答案 1 :(得分:-1)
我知道这可能听起来很奇怪,但我曾经看到过这样的错误。尝试删除django.contrib.sites。它正在与该人安装的另一个应用程序相撞。