我尝试运行时收到此错误
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'
)
答案 0 :(得分:0)
该错误清除表明settings.MIDDLEWARE为None,但您已发布MIDDLEWARE_CLASSES,该类已从Django 2.0中删除。如果django的版本> = 2.0,请确保在settings.py中使用MIDDLEWARE。