该网站工作正常,但当我切换到http://127.0.0.1:8000/admin/时,它在/ admin /显示了AttributeError。我试图在mysite / settings.py中包含MIDDLEWARE_CLASSES,但无济于事。以下是一些细节:
Django mysite.settings
INSTALLED_APPS = [
'personal',
'blog',
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
]
MIDDLEWARE_CLASSES = [
'django.contrib.sessions.middleware.SessionMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.middleware.security.SecurityMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
]
http://127.0.0.1:8000/admin/ page ::
Django mysite.urls ::
from django.conf.urls import url, include
from django.contrib import admin
urlpatterns = [
url(r'^admin/', admin.site.urls),
url(r'^', include('personal.urls')),
url(r'^blog/', include('blog.urls')),
]
我错过了什么吗?如果需要,请询问更多信息。
谢谢!
答案 0 :(得分:2)
您应该知道,更改中间件的顺序可能会导致严重的问题,这在您的情况下会发生。
所以我的建议是在INSTALLED_APPS
的末尾添加你的应用程序并创建一个新的django项目并用新创建的项目的中间件列表替换你的中间件列表或尝试使用这些
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',
'django.middleware.locale.LocaleMiddleware',
]