当我尝试使用超级用户ID和密码登录Django管理面板时,出现运行时错误:“模型类django.contrib.sessions.models.Session没有声明显式的app_label,并且不在INSTALLED_APPS中的应用程序中。”该怎么办?
我已经尝试将“django.contrib.sites”添加到INSTALLED_APPS和SITE_ID = 1中,如一些解决方案所示,但它没有起作用。
我的settings.py看起来像这样:
INSTALLED_APPS = [
'newsfeed',
'user_profile',
'django.contrib.sites',
'Alumni_Portal.apps.AlumniPortalConfig',
'django.contrib.admin',
'django.contrib.auth',
#'django.contrib.sites',
'django_extensions',
'django.contrib.contenttypes',
#'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
]
SITE_ID = 1
MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware',
'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 = 'NSU_Alumni_Portal.urls'
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [os.path.join(BASE_DIR, 'templates')],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
],
},
},
] ```
'django.contrib.sessions',
添加到INSTALLED_APPS
(取消注释)。 - Willem Van Onsem