Django admin DoesNotExist at/admin /

cre*_*ive 24 django

我有一些Django管理员的问题.

在syncdb之后,结果是:

  Creating tables ...
  Installing custom SQL ...
  Installing indexes ...
  No fixtures found.
Run Code Online (Sandbox Code Playgroud)

这是什么意思?

无论如何,当我访问网站管理员面板http://www.example.com/admin/时,我收到以下消息:

DoesNotExist at /admin/
Site matching query does not exist.
Run Code Online (Sandbox Code Playgroud)

setting.py包含:

INSTALLED_APPS = (
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.sites',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    # Uncomment the next line to enable the admin:
    'django.contrib.admin',
)
Run Code Online (Sandbox Code Playgroud)

ur.py包含:

from django.conf.urls.defaults 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'^$', 'rshd.views.home', name='home'),
    # url(r'^rshd/', include('rshd.foo.urls')),

    # Uncomment the admin/doc line below to enable admin documentation:
     url(r'^admin/doc/', include('django.contrib.admindocs.urls')),

    # Uncomment the next line to enable the admin:
     url(r'^admin/', include(admin.site.urls)),
)
Run Code Online (Sandbox Code Playgroud)

Ram*_*ngh 75

sites如果您只从项目中运行一个站点,则不需要该框架,因此最简单的修复方法是从您的项目中删除以下项目,INSTALLED_APPS错误应该消失:

'django.contrib.sites'
Run Code Online (Sandbox Code Playgroud)

您还可以从shell重新创建缺少的Site对象.运行python manage.py shell然后:

from django.contrib.sites.models import Site
Site.objects.create(pk=1, domain='www.example.com', name='example.com')
Run Code Online (Sandbox Code Playgroud)

  • 如果您使用的是''django.contrib.sites',请确保在settings.py中已经定义了`SITE_ID = 1`. (13认同)
  • 嘿,我也有同样的问题.但对我来说,管理员之前工作过.当我再次检查管理页面时,它突然停止工作,直到我重新创建了丢失的站点对象.你碰巧知道问题是什么吗?为什么我突然重新创建了丢失的物体? (3认同)

Tar*_*aji 7

如果您使用django.contrib.sites 而不通过更改文件中的SITE_ID = 1值来删除它,则可以修复此错误settings.py.

当我在我的服务器上更改域名时,我发生了这种情况,我http://mynewdomainname.com/admin/sites/site/手动删除了旧域名,并且数据库中的旧域名记录了id = 1,我也添加了新的域名mynewdomainname.com,它是id id = 2, 我只是更改为了SITE_ID = 2错误已删除SITE_ID是指您默认使用的活动域名的当前"pk".在代码中:

>>> from django.contrib.sites.models import Site
>>> # get_current() came from SiteManager class manager, 
>>> # see site-packages/django/contrib/sites/models.py
>>> current_site = Site.objects.get_current()
>>> print(current_site.pk)
2
>>> print(current_site.domain)
'http://mynewdomainname.com'
Run Code Online (Sandbox Code Playgroud)

这发生在settings.py改变之后

SITE_ID = 2
Run Code Online (Sandbox Code Playgroud)

请注意django sites app中的当前域ID .