Django中间件错误-中间件已更改为1.7 [英] Django Middleware Error - Middleware changed for 1.7
问题描述
每当我在django项目中运行本地服务器时,都会收到警告和错误消息,指出在Django 1.7中全局中间件类已更改-即使我使用的是1.8。我的博客位于 http://127.0.0.1:8000/ ,可以正常加载,但是当我尝试加载时在管理站点,我在/ admin /'WSGIRequest'对象中得到 AttributeError,没有属性'user'
,据我所知这与中间件有关。感谢您的提前帮助
Whenever I run my local server with my django project I am getting a warning and an error message saying that in Django 1.7 the global middleware classes were changed - even though I am using 1.8. My blog, at http://127.0.0.1:8000/, loads fine, but when I try to load the admin site I get AttributeError at /admin/ 'WSGIRequest' object has no attribute 'user'
, which as far as I can tell is to do with the Middleware. Thanks for your help in advance
编辑:我的中间件:
MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
]
错误消息:
Warnings
?: (1_7.W001) Middleware_Classes is not set.
Hint: Django 1.7 changed the global defaults for the middleware_classes. django.contrib.auth.middleware.AuthenticationMiddleware, django.contrib.sessions.middleware.SessionMiddleware, and django.contrib.messages.middleware.MessageMiddleware, were removed from the defaults. If your project needs this middleware then you should configure this middleware.
推荐答案
MIDDLEWARE
设置在Django 1.10中引入。如果您使用的是Django 1.9或更早版本,则它将无效,并且应该使用 MIDDLEWARE_CLASSES
设置。
The MIDDLEWARE
setting was introduced in Django 1.10. If you are using Django 1.9 or earlier it will have no effect, and you should be using the MIDDLEWARE_CLASSES
setting instead.
确保您使用的文档版本正确(例如 Django 1.8 , Django 1.11 ),这样您就可以遵循正确的指示。
Make sure you are using the correct version of the docs (e.g. Django 1.8, Django 1.11), so that you follow the correct instructions.
这篇关于Django中间件错误-中间件已更改为1.7的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!