2

我正在使用 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
4

3 回答 3

6

它在django 1.4.2+上运行良好,我使用的是 django1.4 然后升级它

pip install django==1.4.5 --upgrade
于 2014-01-07T06:50:55.213 回答
2

Django 1.3有问题smart_bytes,从您的回溯中它显示相同的错误,它已在Django 1.4中解决,尝试将Django升级到最新版本1.5

于 2013-10-30T07:37:30.877 回答
0

https://github.com/django/django/blob/master/django/utils/encoding.py#L149

此外,在升级 Django 之前,请务必查看发行说明。

更新:

很抱歉,哇,真是个脑残;)。

我不知道该函数的完整历史,但查看 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 文件以使用你所拥有的。

于 2013-10-30T07:45:21.970 回答