我有一些关于Django管理的问题。
在syncdb之后,结果是:
Creating tables ...
Installing custom SQL ...
Installing indexes ...
No fixtures found.这是什么意思?
无论如何,当我访问网站管理面板http://www.example.com/admin/时,我收到以下消息:
DoesNotExist at /admin/
Site matching query does not exist.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',
)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)),
)发布于 2012-03-16 20:36:04
如果您只从项目中运行一个站点,那么您实际上并不需要sites框架,所以最简单的修复方法是从您的INSTALLED_APPS中删除以下项,这样错误就会消失:
'django.contrib.sites'也可以从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')发布于 2018-01-25 17:06:34
如果您在使用django.contrib.sites 时没有使用,则可以通过更改settings.py文件中的SITE_ID = 1值来删除它,从而修复此错误。
当我在我的服务器上更改域名时发生了这种情况,我手动从http://mynewdomainname.com/admin/sites/site/中删除了旧域名,数据库中的旧域名记录有id = 1,而且我添加了新域名mynewdomainname.com,它的id是id = 2,我刚刚更改为 SITE_ID = 2 ,错误gone 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'这发生在settings.py更改之后
SITE_ID = 2在django sites app中要注意当前的域名id。
发布于 2013-03-15 15:22:23
同样的问题也突然出现在我的脑海中,你知道有很多解决方案。但是,这个突如其来的问题是什么原因呢?
经过深入挖掘,我发现原因是,我们忽略了第一个syncdb操作中的一个步骤。
当你有你的第一个syncdb,django会要求你创建一个默认帐户,如果你不在这个互动节目中输入,该站点对象将不会自动创建。
所以要小心这一点。我使用的是django 1.3.1,不知道最新版本是否解决了这个问题。
https://stackoverflow.com/questions/9736975
复制相似问题