Django Middleware Error - Middleware changed for 1.7(Django 中间件错误 - 为 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 更改了中间件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:Django 中间件错误 - 为 1.7 更改了中间件
![](/xwassets/images/pre.png)
![](/xwassets/images/next.png)
- pytorch 中的自适应池是如何工作的? 2022-07-12
- 沿轴计算直方图 2022-01-01
- 如何在 Python 的元组列表中对每个元组中的第一个值求和? 2022-01-01
- python-m http.server 443--使用SSL? 2022-01-01
- 使用Heroku上托管的Selenium登录Instagram时,找不到元素';用户名'; 2022-01-01
- 如何将一个类的函数分成多个文件? 2022-01-01
- python check_output 失败,退出状态为 1,但 Popen 适用于相同的命令 2022-01-01
- padding='same' 转换为 PyTorch padding=# 2022-01-01
- 如何在 python3 中将 OrderedDict 转换为常规字典 2022-01-01
- 分析异常:路径不存在:dbfs:/databricks/python/lib/python3.7/site-packages/sampleFolder/data; 2022-01-01