1

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 ofexample.com`があります

4

2 に答える 2

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ます)、それが問題です。django.contrib.sitesSITE_IDを使用していない場合は不要な を設定しないことで解決できます。

于 2012-04-10T13:29:17.743 に答える
-1

奇妙に聞こえるかもしれませんが、このようなエラーを一度見ました。django.contrib.sites を削除してみてください。その人がインストールした別のアプリと衝突していました。

于 2012-04-10T11:30:15.663 に答える