django-seo setting up, models aren't loaded yet

匆匆过客 提交于 2020-01-25 10:59:46

问题


I'm trying to add django-seo into my site. But I can't cope with setting up. I followed instructions documentation, but error occurs.

This is what I did:

  1. Installed django-seo packacge
  2. Added rollyourown.seo to INSTALED_APPS
  3. Created seo.py file in my site content app

And this is what I wrote into seo.py file:

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',)

When Meta class is removed, I can't add any meta tags to contnet via Django Admin Site( I registered it in admin site ). I've read that django-seo use get_absolute_url() to deal with it. But in my site app I don't use this function for provide more some utilities to multilanguage.

But if i add Meta class, i will get this error:

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.

I tried diffrent solutions but nothing helped.


回答1:


Django-SEO is not compatible with Django 1.7, which is the first version of Django that includes the AppRegistry.

Either rollback to Django 1.6.x or remove Django-SEO.




回答2:


I got it working by changing get_query_set() to get_queryset()(changed in django1.8) in file rollyourown\seo\backends.py




回答3:


As original Django-SEO is not supported anymore, these guys made and support their own version / fork of Django-SEO. I use it with Django 1.8.8, Python 3 is supported too. https://github.com/whyflyru/django-seo



来源:https://stackoverflow.com/questions/29015988/django-seo-setting-up-models-arent-loaded-yet

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!