0
我正在創建一個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_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我的網站模式是這樣的:
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,我不知道如何解決它。
在此先感謝。
我在Django很新,我該怎麼設置呢?爲了澄清,網站是我的數據庫中的一個表格來描述一個地方。它會在「網站」框架中產生錯誤嗎? – meikse 2014-10-21 13:59:05
只需在您的settings.py中添加SITE_ID = x :) 網站框架使用了一個非常纖細的站點表,它必須遷移才能顯示在您的數據庫中。 – ACimander 2014-10-21 19:25:43
謝謝。錯誤解決了,我可以進入django管理。我在我的數據庫上創建了一個名爲「Site」的表格。如果有網站框架,我希望這不會成爲問題。 – meikse 2014-10-21 21:13:48