安装了django-axes,但是axis.middleware模块不可用

时间:2016-08-05 09:55:03

标签: python django

我最近重构了很多代码,想要一个干净的环境,所以我删除并重新创建了数据库模式,创建了一个新的venv,并逐个安装pip3的依赖项,所以我没有从旧环境遗留下来的任何多余的包裹。我快速安装了六打包,然后migrate通过了。但是,runserver抱怨找不到axes.middleware(已安装)。

  • 我在我的虚拟环境中安装了django-axes 2.2.0(编辑:python 3.5,django 1.10)。
  • 我在pip3 freeze后验证了安装是否存在 卸载并重新安装只是为了确保。 django-axes==2.2.0
  • 我在axes
  • 中列出了INSTALLED_APPS
  • 我在axes.middleware.FailedLoginMiddleware中列出了MIDDLEWARE_CLASSES请注意,如果我注释掉此行,则django不会尝试导入axes.middleware,因此runserver会成功。

  • 我可以在shell上执行import axes; axes.get_version()from axes.decorators import watch_login,所以很明显,环境可以使用轴。

这里出了什么问题?

追溯自 ./manage.py runserver

Unhandled exception in thread started by <function check_errors.<locals>.wrapper at 0x7f2d43a381e0>
Traceback (most recent call last):
  File "/webapps/my_app/lib/python3.5/site-packages/django/core/servers/basehttp.py", line 49, in get_internal_wsgi_application
    return import_string(app_path)
  File "/webapps/my_app/lib/python3.5/site-packages/django/utils/module_loading.py", line 20, in import_string
    module = import_module(module_path)
  File "/usr/lib/python3.5/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 986, in _gcd_import
  File "<frozen importlib._bootstrap>", line 969, in _find_and_load
  File "<frozen importlib._bootstrap>", line 958, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 673, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 665, in exec_module
  File "<frozen importlib._bootstrap>", line 222, in _call_with_frames_removed
  File "/webapps/my_app/wsgi.py", line 14, in <module>
    application = get_wsgi_application()
  File "/webapps/my_app/lib/python3.5/site-packages/django/core/wsgi.py", line 14, in get_wsgi_application
    return WSGIHandler()
  File "/webapps/my_app/lib/python3.5/site-packages/django/core/handlers/wsgi.py", line 153, in __init__
    self.load_middleware()
  File "/webapps/my_app/lib/python3.5/site-packages/django/core/handlers/base.py", line 56, in load_middleware
    mw_class = import_string(middleware_path)
  File "/webapps/my_app/lib/python3.5/site-packages/django/utils/module_loading.py", line 20, in import_string
    module = import_module(module_path)
  File "/usr/lib/python3.5/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 986, in _gcd_import
  File "<frozen importlib._bootstrap>", line 969, in _find_and_load
  File "<frozen importlib._bootstrap>", line 956, in _find_and_load_unlocked
ImportError: No module named 'axes.middleware'

1 个答案:

答案 0 :(得分:7)

从2.0.0开始,django-axes有default_app_config所以你可以在不安装中间件的情况下在INSTALLED_APPS中使用轴。因此,请删除settings.py

中的相关MIDDLEWARE_CLASSES