【发布时间】:2019-07-25 12:50:39
【问题描述】:
我在尝试运行时遇到此错误
python manage.py runserver
或命令行中的任何其他 python manage.py * 命令。
但是当我尝试 python manage.py shell 时,它没有错误地连接并从数据库中获取数据。
错误:
Unhandled exception in thread started by <function check_errors.<locals>.wrapper at 0x7fa03b7386a8>
Traceback (most recent call last):
File "/home/tornike/apps/env/lib/python3.6/site-packages/django/utils/autoreload.py", line 227, in wrapper
fn(*args, **kwargs)
File "/home/tornike/apps/env/lib/python3.6/site-packages/django/core/management/commands/runserver.py", line 125, in inner_run
self.check(display_num_errors=True)
File "/home/tornike/apps/env/lib/python3.6/site-packages/django/core/management/base.py", line 359, in check
include_deployment_checks=include_deployment_checks,
File "/home/tornike/apps/env/lib/python3.6/site-packages/django/core/management/base.py", line 346, in _run_checks
return checks.run_checks(**kwargs)
File "/home/tornike/apps/env/lib/python3.6/site-packages/django/core/checks/registry.py", line 81, in run_checks
new_errors = check(app_configs=app_configs)
File "/home/tornike/apps/env/lib/python3.6/site-packages/debug_toolbar/apps.py", line 25, in check_middleware
for i, middleware in enumerate(settings.MIDDLEWARE):
TypeError: 'NoneType' object is not iterable
MIDDLEWARE_CLASSES = (
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.locale.LocaleMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
'django.middleware.security.SecurityMiddleware'
)
【问题讨论】:
-
您是否在
settings.py中设置了MIDDLEWARE设置? -
从错误中可以明显看出
settings.MIDDLEWARE是None。 为什么是None,从您提供的信息中我们无法判断。它很可能没有在settings.py中定义 -
@WillemVanOnsem 你什么意思?
-
@DeepSpace 我更新了我的问题,这是我在 settings.py 中的中间件。在另一台电脑上它可以完美运行。
-
@I.Jokhadze:不,这些是
MIDDLEWARE_CLASSES。那就是“旧式”。你应该把它重命名为MIDDLEWARE。