在/ admin /错误处配置不正确

时间:2014-10-20 21:41:42

标签: python django django-admin

我正在创建一个Django应用程序而我正在尝试设置界面管理。但是当我运行管理员网址时,我收到了错误消息。我在这里已经多次看过这个问题并且我一直在尝试不同的解决方案,但没有一个适合我。我得到的错误是:

ImproperlyConfigured at /admin/
You're using the Django "sites framework" without having set the SITE_ID setting. Create a site in your database and set the SITE_ID setting to fix this error.

Site是我的数据库中用于描述地点的表,SITE_ID是其ID,它是在我的django文件和我的数据库中创建的。

我的urls.py文件是:

urlpatterns = patterns('',
   (r'^$', mydb),  
    (r'^mydb/$', mydb),  
    (r'^time/$', current_datetime),

# Uncomment the next line to enable the admin:
(r'^admin/', include(admin.site.urls)),
)

我的settings.py配置为:

DEBUG = True

TEMPLATE_DEBUG = True

ALLOWED_HOSTS = []

INSTALLED_APPS = (
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.messages',
'django.contrib.staticfiles',
"mydb",
)

MIDDLEWARE_CLASSES = (
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
)

ROOT_URLCONF = 'mydb.urls'

WSGI_APPLICATION = 'mydb.wsgi.application'

DATABASES = {
'default': {
    'ENGINE': 'django.db.backends.mysql',   # Which database engine to use
    'NAME': 'mydb',                   # The name of the database
    'USER': 'root',                         # The username to use when connecting to the database
    'PASSWORD': 'mypassword',           # The password to use when connecting to your database
    'HOST': '',                             # The host to use when connecting to the database. Set empty string for localhost
    'PORT': '3306',                         # The port to use when connecting to the database. Set empty string for default
}
}

LANGUAGE_CODE = 'en-CA'

TIME_ZONE = 'America/Montreal'

USE_I18N = True

USE_L10N = True

USE_TZ = True

STATIC_URL = '/static/'

STATICFILES_DIRS = (
os.path.join(BASE_DIR, 'static').replace('\\','/'),
)

TEMPLATE_DIRS = (
os.path.join(BASE_DIR, 'templates').replace('\\','/'),
)

models.py上的我的SITE模型如下:

class Site(models.Model):
site_id = models.IntegerField(db_column='Site_ID', primary_key=True) # Field name made lowercase.
site_name = models.CharField(db_column='Site_name', max_length=100) # Field name made lowercase.
site_type = models.TextField(db_column='Site_type') # Field name made lowercase.
watershed = models.ForeignKey('Watershed', db_column='Watershed_ID', blank=True, null=True) # Field name made lowercase.
description = models.TextField(db_column='Description') # Field name made lowercase.
picture = models.TextField(db_column='Picture', blank=True) # Field name made lowercase.
street_number = models.CharField(db_column='Street_number', max_length=100, blank=True) # Field name made lowercase.
street_name = models.CharField(db_column='Street_name', max_length=100, blank=True) # Field name made lowercase.
city = models.TextField(db_column='City', blank=True) # Field name made lowercase.
zip_code = models.CharField(db_column='Zip_code', max_length=100, blank=True) # Field name made lowercase.
province = models.TextField(db_column='Province') # Field name made lowercase.
country = models.TextField(db_column='Country') # Field name made lowercase.
class Meta:
    managed = False
    db_table = 'site'

所有人都被调用到admin.py文件:

from django.contrib import admin
from app.models import Site

admin.site.register(Site)

我已将其他表格放入数据库,但(目前)我刚刚使用此ID收到此错误,而且我不知道如何修复它。

提前致谢。

1 个答案:

答案 0 :(得分:3)

您忘了在设置文件中设置SITE_ID。

您不需要自定义网站模型,它内置于:)

from django.contrib.sites.models import Site