ModuleNotFoundError:No module named 'debug_toolbar' Django 3.1

bvuwiixz  于 2023-06-25  发布在  Go
关注(0)|答案(2)|浏览(134)

我正面临着一个“共同”的问题,显然,因为我搜索,并找到了几个主题。没有一个答案对我有用,因为我已经做了提到的一切。
1.我设置了虚拟环境
1.然后,我安装了django-degub-toolbar
pip install django-debug-toolbar
1.在设置中添加应用程序

INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    # External apps
    'debug_toolbar',
    # Internal apps
    ...,
]

1.并编辑了中间件

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 Toolbar interaction with the middleware
    'debug_toolbar.middleware.DebugToolbarMiddleware',
]

但是什么都不起作用,当我运行服务器时,我仍然得到错误。
回溯

Exception in thread django-main-thread:
Traceback (most recent call last):
  File "/Users/saiko-san/Documents/app-mangas-collection/venv/lib/python3.7/site-packages/django/core/servers/basehttp.py", line 45, in get_internal_wsgi_application
    return import_string(app_path)
  File "/Users/saiko-san/Documents/app-mangas-collection/venv/lib/python3.7/site-packages/django/utils/module_loading.py", line 17, in import_string
    module = import_module(module_path)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/importlib/__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
  File "<frozen importlib._bootstrap>", line 983, in _find_and_load
  File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 677, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 728, in exec_module
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "/Users/saiko-san/Documents/app-mangas-collection/mangas_collection/mangas_collection/wsgi.py", line 16, in <module>
    application = get_wsgi_application()
  File "/Users/saiko-san/Documents/app-mangas-collection/venv/lib/python3.7/site-packages/django/core/wsgi.py", line 13, in get_wsgi_application
    return WSGIHandler()
  File "/Users/saiko-san/Documents/app-mangas-collection/venv/lib/python3.7/site-packages/django/core/handlers/wsgi.py", line 127, in __init__
    self.load_middleware()
  File "/Users/saiko-san/Documents/app-mangas-collection/venv/lib/python3.7/site-packages/django/core/handlers/base.py", line 40, in load_middleware
    middleware = import_string(middleware_path)
  File "/Users/saiko-san/Documents/app-mangas-collection/venv/lib/python3.7/site-packages/django/utils/module_loading.py", line 17, in import_string
    module = import_module(module_path)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/importlib/__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
  File "<frozen importlib._bootstrap>", line 983, in _find_and_load
  File "<frozen importlib._bootstrap>", line 953, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
  File "<frozen importlib._bootstrap>", line 983, in _find_and_load
  File "<frozen importlib._bootstrap>", line 965, in _find_and_load_unlocked
ModuleNotFoundError: No module named 'debug_toolbar'
juud5qan

juud5qan1#

您是否激活了虚拟环境?如果没有请先用命令pipenv shell激活

kmbjn2e3

kmbjn2e32#

我遇到了一个多个python可执行文件的错误。将以下行添加到您的代码中,以检查它正在使用哪个可执行文件:

import sys
print(f"Using this python executable: {sys.executable}")

假设它输出/some/path/bin/python3。然后为该可执行文件安装django-debug-toolbar

/some/path/bin/python3 -m pip install django-debug-toolbar

相关问题