我正在使用django 1.3版 . Python manage.py runserver 0.0.0.0:8000给出以下错误 .
Validating models...
Unhandled exception in thread started by < bound method Command.inner_run of < django.contrib.staticfiles.management.commands.runserver.Command object at 0x20eb110>>
Traceback (most recent call last):
File "/usr/local/lib/python2.7/dist-packages/django/core/management/commands/runserver.py", line 88, in inner_run
self.validate(display_num_errors=True)
File "/usr/local/lib/python2.7/dist-packages/django/core/management/base.py", line 249, in validate
num_errors = get_validation_errors(s, app)
File "/usr/local/lib/python2.7/dist-packages/django/core/management/validation.py", line 36, in get_validation_errors
for (app_name, error) in get_app_errors().items():
File "/usr/local/lib/python2.7/dist-packages/django/db/models/loading.py", line 146, in get_app_errors
self._populate()
File "/usr/local/lib/python2.7/dist-packages/django/db/models/loading.py", line 64, in _populate
self.load_app(app_name)
File "/usr/local/lib/python2.7/dist-packages/django/db/models/loading.py", line 78, in load_app
models = import_module('.models', app_name)
File "/usr/local/lib/python2.7/dist-packages/django/utils/importlib.py", line 35, in import_module
__import__(name)
File "/usr/local/lib/python2.7/dist-packages/tastypie/models.py", line 6, in <module>
from tastypie.utils import now
File "/usr/local/lib/python2.7/dist-packages/tastypie/utils/__init__.py", line 1, in <module>
from tastypie.utils.dict import dict_strip_unicode_keys
File "/usr/local/lib/python2.7/dist-packages/tastypie/utils/dict.py", line 1, in <module>
from django.utils.encoding import smart_bytes
ImportError: cannot import name smart_bytes
3 回答
Django 1.3 有
smart_bytes
的问题,并且从你的回溯它显示相同的错误,它已在 Django 1.4 中解决,尝试将 Django 升级到最新版本的 1.5 .它与django 1.4.2+工作正常,我使用django1.4然后升级它
见https://github.com/django/django/blob/master/django/utils/encoding.py#L149
另外,在升级Django之前,请务必检查release notes .
更新:
对不起,哇,什么是脑力;) .
我不知道该函数的完整历史,但在Github上查看django.utils.encoding ..标记为1.3.7;此文件不包含Tastypie尝试导入的功能 . https://github.com/django/django/blob/1.3.7/django/utils/encoding.py
如果您无法升级Django,则需要修补Tastypie.utils.dict文件以使用您拥有的内容 .