Django debug toolbar import error of analysisdebug_toolbar

六月ゝ 毕业季﹏ 提交于 2019-11-27 07:33:42

问题


Trying to install the django debug toolbar and receiving the following error:

Traceback (most recent call last):
  File "/home/user/project/manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
  File "/home/user/project/env/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 338, in execute_from_command_line
    utility.execute()
  File "/home/user/project/env/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 312, in execute
django.setup()
  File "/home/user/project/env/local/lib/python2.7/site-packages/django/__init__.py", line 18, in setup
apps.populate(settings.INSTALLED_APPS)
  File "/home/user/project/env/local/lib/python2.7/site-packages/django/apps/registry.py", line 85, in populate
app_config = AppConfig.create(entry)
  File "/home/user/project/env/local/lib/python2.7/site-packages/django/apps/config.py", line 86, in create
module = import_module(entry)
  File "/usr/lib/python2.7/importlib/__init__.py", line 37, in import_module
__import__(name)
ImportError: No module named analysisdebug_toolbar

Package versions:

Django==1.8.2
django-debug-toolbar==1.3.0

Funny thing is this used to work but somehow broke due to some changes in the project.


回答1:


It looks like you are missing a comma in your INSTALLED_APPS setting.

Instead of:

INSTALLED_APPS = (
    ...
    'analysis'
    'debug_toolbar',
    ...
)

It should be:

INSTALLED_APPS = (
    ... 
    'analysis',
    'debug_toolbar',
    ...
)

When you forget the comma, Python concatonates 'analysis' and 'debug_toolbar' into the string analysisdebug_toolbar. In Python, it's a good idea to include a trailing comma in the last element in your list or tuple. It allows you to add new items or rearrange the order without hitting bugs like this.



来源:https://stackoverflow.com/questions/34068990/django-debug-toolbar-import-error-of-analysisdebug-toolbar

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!