0

我是 Django 的新手。尝试从 django==1.8.5 迁移到 1.11
django-hvad 包对我来说是必不可少的,但是,当升级到 django==1.10 时,它会抛出关于 Django 版本的断言错误。

Unhandled exception in thread started by <function check_errors.<locals>.wrapper at 0x7f407d733b70>
Traceback (most recent call last):
  File "/home/riddle/pro/blog/env/lib/python3.6/site-packages/django/utils/autoreload.py", line 226, in wrapper
    fn(*args, **kwargs)
  File "/home/riddle/pro/blog/env/lib/python3.6/site-packages/django/core/management/commands/runserver.py", line 113, in inner_run
    autoreload.raise_last_exception()
  File "/home/riddle/pro/blog/env/lib/python3.6/site-packages/django/utils/autoreload.py", line 249, in raise_last_exception
    six.reraise(*_exception)
  File "/home/riddle/pro/blog/env/lib/python3.6/site-packages/django/utils/six.py", line 685, in reraise
    raise value.with_traceback(tb)
  File "/home/riddle/pro/blog/env/lib/python3.6/site-packages/django/utils/autoreload.py", line 226, in wrapper
    fn(*args, **kwargs)
  File "/home/riddle/pro/blog/env/lib/python3.6/site-packages/django/__init__.py", line 27, in setup
    apps.populate(settings.INSTALLED_APPS)
  File "/home/riddle/pro/blog/env/lib/python3.6/site-packages/django/apps/registry.py", line 108, in populate
    app_config.import_models(all_models)
  File "/home/riddle/pro/blog/env/lib/python3.6/site-packages/django/apps/config.py", line 199, in import_models
    self.models_module = import_module(models_module_name)
  File "/home/riddle/pro/blog/env/lib/python3.6/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 994, in _gcd_import
  File "<frozen importlib._bootstrap>", line 971, in _find_and_load
  File "<frozen importlib._bootstrap>", line 955, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 665, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 678, in exec_module
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "/home/riddle/pro/blog/app/apps/frontend/website/models.py", line 116, in <module>
    class ContentBlock(Common, TranslatableModel, OrderedModel):
  File "/home/riddle/pro/blog/env/lib/python3.6/site-packages/django/db/models/base.py", line 309, in __new__
    new_class._prepare()
  File "/home/riddle/pro/blog/env/lib/python3.6/site-packages/django/db/models/base.py", line 359, in _prepare
    signals.class_prepared.send(sender=cls)
  File "/home/riddle/pro/blog/env/lib/python3.6/site-packages/django/dispatch/dispatcher.py", line 191, in send
    response = receiver(signal=self, sender=sender, **named)
  File "/home/riddle/pro/blog/env/lib/python3.6/site-packages/hvad/models.py", line 447, in prepare_translatable_model
    assert django.VERSION < (1, 10)
AssertionError

我的项目其实是一个单页的网站,所以去掉django-hvad,改用别的也不是什么大麻烦。因此,这是我的问题,采取哪些步骤更好:

(1)尝试使用另一个“应用程序”进行模型翻译,如: https : //djangopackages.org/grids/g/model-translation/(但是,正如我所见,那里只有一个包支持 Django1.10)。

(2) 或者 Django 有一个我应该使用的本地模型翻译选项。

(3) 另一种选择

奇怪的是https://django-hvad.readthedocs.io/en/latest/index.html表明 django1.9 是最后一个支持的版本,但是在 GitHub 页面https://github.com/kristianoellegaard/ django-hvad支持 django 1.10 和 django 1.11。

请指出需要更多信息,我会尽力提供。

我的点冻结输出:

Django==1.10
django-appconf==1.0.2
django-compressor==2.2
django-filebrowser-no-grappelli==3.7.4
django-geoposition==0.3.0
django-hvad==1.8.0
django-jquery==3.1.0
django-libsass==0.7
django-ordered-model==1.4.3
django-tinymce==2.7.0
libsass==0.14.2
Pillow==5.1.0
psycopg2-binary==2.7.4
pytz==2018.3
rcssmin==1.0.6
rjsmin==1.0.12
six==1.11.0

django-hvad 的用法(示例):

from hvad.models import TranslatableModel, TranslatedFields

class SliderBox(TranslatableModel, OrderedModel):

translations = TranslatedFields(
    image = FileBrowseField(
            "Image",
            max_length=200,
            directory="uploads/",
            extensions=[".png", ".jpg"],
            blank=True,
            null=True
    ),
    text = models.CharField(max_length=200),
)
4

0 回答 0