gpt4 book ai didi

python - Django 管理错误

转载 作者:行者123 更新时间:2023-12-01 06:01:44 25 4
gpt4 key购买 nike

修改django-userenasettings.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.

你知道是什么原因导致这个错误吗?

编辑

按照 huck Harmston 说明 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/',这是我使用的域名,而不是example.com`

最佳答案

您的 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 则不需要设置。 .

关于python - Django 管理错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10087201/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com