我试图将django-seo添加到我的网站中。但我无法应对设置。我按照说明文档,但发生错误。
这就是我所做的:
这就是我写入seo.py文件的内容:
from rollyourown import seo
class Metadata(seo.Metadata):
title = seo.Tag(head=True, max_length=68)
description = seo.MetaTag(max_length=155)
keywords = seo.KeywordTag()
heading = seo.Tag(name="h1")
class Meta:
seo_views = ('SiteContent',)
seo_models = ('SiteContent',)
删除Meta类后,我无法通过Django管理站点向contnet添加任何元标记(我在管理站点中注册)。我读过django-seo使用get_absolute_url()来处理它。但是在我的网站应用中,我没有使用此功能为多语言提供更多实用工具。
但如果我添加Meta类,我会收到此错误:
Traceback (most recent call last):
File "F:/Site/manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "F:\Python27\lib\site-packages\django\core\management\__init__.py", line 385, in execute_from_command_line
utility.execute()
File "F:\Python27\lib\site-packages\django\core\management\__init__.py", line 354, in execute
django.setup()
File "F:\Python27\lib\site-packages\django\__init__.py", line 21, in setup
apps.populate(settings.INSTALLED_APPS)
File "F:\Python27\lib\site-packages\django\apps\registry.py", line 108, in populate
app_config.import_models(all_models)
File "F:\Python27\lib\site-packages\django\apps\config.py", line 202, in import_models
self.models_module = import_module(models_module_name)
File "F:\Python27\lib\importlib\__init__.py", line 37, in import_module
__import__(name)
File "F:\Python27\lib\site-packages\djangoseo-1.0-py2.7.egg\rollyourown\seo\models.py", line 10, in <module>
__import__(module_name)
File "F:\Site\SiteContent\seo.py", line 5, in <module>
class Metadata(seo.Metadata):
File "F:\Python27\lib\site-packages\djangoseo-1.0-py2.7.egg\rollyourown\seo\base.py", line 166, in __new__
options = Options(Meta, help_text)
File "F:\Python27\lib\site-packages\djangoseo-1.0-py2.7.egg\rollyourown\seo\options.py", line 19, in __init__
self._set_seo_models(meta.pop('seo_models', []))
File "F:\Python27\lib\site-packages\djangoseo-1.0-py2.7.egg\rollyourown\seo\options.py", line 96, in _set_seo_models
seo_models.extend(models.get_models(app))
File "F:\Python27\lib\site-packages\django\db\models\__init__.py", line 54, in alias
return getattr(loading, function_name)(*args, **kwargs)
File "F:\Python27\lib\site-packages\django\utils\lru_cache.py", line 101, in wrapper
result = user_function(*args, **kwds)
File "F:\Python27\lib\site-packages\django\apps\registry.py", line 168, in get_models
self.check_models_ready()
File "F:\Python27\lib\site-packages\django\apps\registry.py", line 131, in check_models_ready
raise AppRegistryNotReady("Models aren't loaded yet.")
django.core.exceptions.AppRegistryNotReady: Models aren't loaded yet.
我尝试了不同的解决方案,但没有任何帮助。
答案 0 :(得分:0)
Django-SEO与Django 1.7不兼容,Django 1.7是包含AppRegistry
的Django的第一个版本。
回滚到Django 1.6.x或删除Django-SEO。
答案 1 :(得分:0)
我通过在文件rollyourown \ seo \ backends.py
中将get_query_set()更改为get_queryset()(在django1.8中更改)来实现它答案 2 :(得分:0)
由于原来的Django-SEO不再受支持,这些人制作并支持他们自己的Django-SEO版本/分支。我在Django 1.8.8中使用它,也支持Python 3。 https://github.com/whyflyru/django-seo