Django ImportError: No module named formtools.wizard.storage 报错解决方案

欢迎大家扫码关注我的微信公众号:
数据之恋

一、 问题描述

当我通过命令行运行 Django 项目服务的时候, 报出如下错误:

root@ubuntu:~/workspace/001-django_xadmin/xadmin-master/demo_app# python manage.py runserver
Unhandled exception in thread started by <function wrapper at 0x7fdd525f7230>
Traceback (most recent call last):
  File "/usr/local/lib/python2.7/dist-packages/django/utils/autoreload.py", line 228, in wrapper
    fn(*args, **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/django/core/management/commands/runserver.py", line 117, in inner_run
    autoreload.raise_last_exception()
  File "/usr/local/lib/python2.7/dist-packages/django/utils/autoreload.py", line 251, in raise_last_exception
    six.reraise(*_exception)
  File "/usr/local/lib/python2.7/dist-packages/django/utils/autoreload.py", line 228, in wrapper
    fn(*args, **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/django/__init__.py", line 27, in setup
    apps.populate(settings.INSTALLED_APPS)
  File "/usr/local/lib/python2.7/dist-packages/django/apps/registry.py", line 116, in populate
    app_config.ready()
  File "/home/cybeyond/workspace/001-django_xadmin/xadmin-master/demo_app/../xadmin/apps.py", line 14, in ready
    self.module.autodiscover()
  File "/home/cybeyond/workspace/001-django_xadmin/xadmin-master/demo_app/../xadmin/__init__.py", line 49, in autodiscover
    register_builtin_plugins(site)
  File "/home/cybeyond/workspace/001-django_xadmin/xadmin-master/demo_app/../xadmin/plugins/__init__.py", line 41, in register_builtin_plugins
    [import_module('xadmin.plugins.%s' % plugin) for plugin in PLUGINS if plugin not in exclude_plugins]
  File "/usr/lib/python2.7/importlib/__init__.py", line 37, in import_module
    __import__(name)
  File "/home/cybeyond/workspace/001-django_xadmin/xadmin-master/demo_app/../xadmin/plugins/wizard.py", line 12, in <module>
    from django.contrib.formtools.wizard.storage import get_storage
ImportError: No module named formtools.wizard.storage

二、 使用环境

我的环境是:
Ubuntu 16.04 + python2.7.6 + Django 1.11.6

三、 解决方案

解决方案很简单, 卸载 formtools, 然后重新安装:
首先卸载:

root@ubuntu:~/workspace/001-django_xadmin/xadmin-master/demo_app# pip uninstall django-formtools
The directory '/home/cybeyond/.cache/pip/http' or its parent directory is not owned by the current user and the cache has been disabled. Please check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
Uninstalling django-formtools-1.0:
  Would remove:
    /usr/local/lib/python2.7/dist-packages/django_formtools-1.0.dist-info/*
    /usr/local/lib/python2.7/dist-packages/formtools/*
Proceed (y/n)? y
  Successfully uninstalled django-formtools-1.0

然后重新安装:

root@ubuntu:~/workspace/001-django_xadmin/xadmin-master/demo_app# pip install django-formtools
The directory '/home/cybeyond/.cache/pip/http' or its parent directory is not owned by the current user and the cache has been disabled. Please check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
The directory '/home/cybeyond/.cache/pip' or its parent directory is not owned by the current user and caching wheels has been disabled. check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
Collecting django-formtools
  Downloading https://files.pythonhosted.org/packages/97/3f/b8e04c41c028d5cdad651393abea1f686d846c717d8ab5d5ebe2974f711c/django_formtools-2.1-py2.py3-none-any.whl (132kB)
    100% |████████████████████████████████| 133kB 644kB/s 
Requirement already satisfied: Django>=1.8 in /usr/local/lib/python2.7/dist-packages (from django-formtools) (1.11.6)
Requirement already satisfied: pytz in /usr/local/lib/python2.7/dist-packages (from Django>=1.8->django-formtools) (2018.7)
Installing collected packages: django-formtools
Successfully installed django-formtools-2.1

最后, 使用命令行运行 Django 服务:

root@ubuntu:~/workspace/001-django_xadmin/xadmin-master/demo_app# python manage.py runserver
Performing system checks...

System check identified no issues (0 silenced).

You have 20 unapplied migration(s). Your project may not work properly until you apply the migrations for app(s): admin, app, auth, contenttypes, reversion, sessions, xadmin.
Run 'python manage.py migrate' to apply them.

December 29, 2018 - 03:50:17
Django version 1.11.6, using settings 'demo.settings'
Starting development server at http://127.0.0.1:8000/
Quit the server with CONTROL-C.

可以发现, 错误信息没有再被报出, Django 服务也运行起来了。

当您在 Django 项目的迁移过程中遇到 `ModuleNotFoundError: No module named 'model.config'` 的错误时,这通常意味着 Django 无法找到名为 `model.config` 的模块。以下是可能的原因和解决步骤: 1. **路径问题**[^1]: - 检查您的 `settings.py` 文件中的 `INSTALLED_APPS` 列表,确保包含了 `'model.config'` 这个应用。如果是导入错误,应确保已正确添加到这个列表里。 ```python INSTALLED_APPS = [ ... 'model.config', # 如果还没添加,这里需要加上 ... ] ``` 2. **模块结构**: - 确认 `model.config` 是否已经存在于项目的正确的文件夹结构中(通常是 `app_name/config.py` 或者 `app_name/models.py`),并且该目录已经在项目的 `PYTHONPATH` 中。 3. **导入语句**: - 确保在需要使用的文件中,导入 `'model.config'` 的方式是正确的。如果是在某个视图或管理器中,可能是: ```python from model.config import YourModelClass ``` 或者 ```python from .config import YourConfigFunction ``` 4. **名称冲突**: - 如果另一个模块已经占用了相同的名称,尝试更改 `model.config` 的名称,以避免导入冲突。 5. **清理缓存**: - 清理并重新加载 Django 的开发服务器 (`python manage.py runserver --clear-cache`) 可能有助于解决因缓存导致的导入问题。 6. **安装依赖**: - 确保已经正确安装了 `model.config` 所需的所有依赖,特别是如果它是一个第三方库,需要通过 pip 安装。 如果以上步骤都不能解决问题,检查是否有其他同名模块干扰,或者是否在项目的 setup.py 文件中正确地指定了模块的入口点。另外,检查 `model.config` 是否已经被正确地添加到了项目的版本控制系统(如 Git)中。
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值