我是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)尝试使用另一个“app”进行模型翻译,如: 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),
)