0

我正在尝试使用 djangotoolbox.fields 中的 Listfield,但它给了我一个错误消息:

Traceback (most recent call last):
File "/Library/Python/2.7/site-packages/django/utils/autoreload.py", line 226, in wrapper
fn(*args, **kwargs)
File "/Library/Python/2.7/site-packages/django/core/management/commands/runserver.py", line 109, in inner_run
autoreload.raise_last_exception()
File "/Library/Python/2.7/site-packages/django/utils/autoreload.py", line 249, in raise_last_exception
six.reraise(*_exception)
File "/Library/Python/2.7/site-packages/django/utils/autoreload.py", line 226, in wrapper
fn(*args, **kwargs)
File "/Library/Python/2.7/site-packages/django/__init__.py", line 18, in setup
apps.populate(settings.INSTALLED_APPS)
File "/Library/Python/2.7/site-packages/django/apps/registry.py", line 108, in populate
app_config.import_models(all_models)
File "/Library/Python/2.7/site-packages/django/apps/config.py", line 202, in import_models
self.models_module = import_module(models_module_name)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/importlib/__init__.py", line 37, in import_module
__import__(name)
File "/Users/coderahul/Desktop/Experiment Box/Innovation/Codeplay/codeplay/data_aggregator/models.py", line 9, in <module>
from djangotoolbox.fields import ListField
File "/Library/Python/2.7/site-packages/djangotoolbox/fields.py", line 4, in <module>
from django.utils.importlib import import_module
ImportError: No module named importlib

我究竟做错了什么?

4

2 回答 2

2

django.utils.importlib 是仍然支持 Python 2.6 时的兼容性库。自 Django 1.7 以来,它已经过时了,它放弃了对 Python 2.6 的支持,并在 1.9 中按弃用周期删除。

尝试这个

from importlib import import_module

来源这里。

于 2017-02-02T08:36:18.810 回答
0

利用from importlib import import_module

于 2017-02-02T08:36:14.673 回答