0

I hit a problem when run django from command line with manage.py runserver.

The same code is fine with Django 1.5 several months ago.

Today I wanna pickup the code again and run upon Django 1.8.3 and python2.7.10 .

Now, got error here:

Traceback (most recent call last):
  File "manage.py", line 29, in <module>
    execute_from_command_line(sys.argv)
  File "/usr/local/lib/python2.7/dist-packages/django/core/management/__init__.py", line 338, in execute_from_command_line
    utility.execute()
  File "/usr/local/lib/python2.7/dist-packages/django/core/management/__init__.py", line 312, in execute
    django.setup()
  File "/usr/local/lib/python2.7/dist-packages/django/__init__.py", line 18, in setup
    apps.populate(settings.INSTALLED_APPS)
  File "/usr/local/lib/python2.7/dist-packages/django/apps/registry.py", line 108, in populate
    app_config.import_models(all_models)
  File "/usr/local/lib/python2.7/dist-packages/django/apps/config.py", line 198, in import_models
    self.models_module = import_module(models_module_name)
  File "/usr/lib/python2.7/importlib/__init__.py", line 37, in import_module
    __import__(name)
  File "/media/wni/study/workspace4320151111/weichun/mytheme/models.py", line 8, in <module>
    from mezzanine.pages.models import Page
  File "/media/wni/study/workspace4320151111/weichun/mezzanine/pages/models.py", line 34, in <module>
    class Page(BasePage):
  File "/media/wni/study/workspace4320151111/weichun/mezzanine/core/models.py", line 350, in __new__
    return super(OrderableBase, cls).__new__(cls, name, bases, attrs)
  File "/usr/local/lib/python2.7/dist-packages/django/db/models/base.py", line 298, in __new__
    new_class.add_to_class(field.name, copy.deepcopy(field))
  File "/usr/local/lib/python2.7/dist-packages/django/db/models/base.py", line 324, in add_to_class
    value.contribute_to_class(cls, name)
  File "/media/wni/study/workspace4320151111/weichun/mezzanine/generic/fields.py", line 226, in contribute_to_class
    super(KeywordsField, self).contribute_to_class(cls, name)
  File "/media/wni/study/workspace4320151111/weichun/mezzanine/generic/fields.py", line 84, in contribute_to_class
    cls._meta.get_fields_with_model()]:
  File "/usr/local/lib/python2.7/dist-packages/django/db/models/options.py", line 56, in wrapper
    return fn(*args, **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/django/db/models/options.py", line 432, in get_fields_with_model
    return [self._map_model(f) for f in self.get_fields()]
  File "/usr/local/lib/python2.7/dist-packages/django/db/models/options.py", line 740, in get_fields
    return self._get_fields(include_parents=include_parents, include_hidden=include_hidden)
  File "/usr/local/lib/python2.7/dist-packages/django/db/models/options.py", line 802, in _get_fields
    all_fields = self._relation_tree
  File "/usr/local/lib/python2.7/dist-packages/django/utils/functional.py", line 60, in __get__
    res = instance.__dict__[self.name] = self.func(instance)
  File "/usr/local/lib/python2.7/dist-packages/django/db/models/options.py", line 709, in _relation_tree
    return self._populate_directed_relation_graph()
  File "/usr/local/lib/python2.7/dist-packages/django/db/models/options.py", line 681, in _populate_directed_relation_graph
    all_models = self.apps.get_models(include_auto_created=True)
  File "/usr/local/lib/python2.7/dist-packages/django/utils/lru_cache.py", line 101, in wrapper
    result = user_function(*args, **kwds)
  File "/usr/local/lib/python2.7/dist-packages/django/apps/registry.py", line 168, in get_models
    self.check_models_ready()
  File "/usr/local/lib/python2.7/dist-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.

Anyone knows how to fix it?

Thanks.

Wesley

Wesley
  • 1,857
  • 2
  • 16
  • 30
  • What version of Mezzanine are you using? – knbk Jul 26 '16 at 15:03
  • Mezzanine is 3.1.9, I know it's old, but I changed some code before, so I don't wanna use the latest version from official. I think I shouldn't need to change lots of code to fix this guy. I wanna change code to run first and then trying to transfer to formal build later on – Wesley Jul 26 '16 at 15:07
  • It seems you need at least 4.0.0 for use with Django 1.8. You need to upgrade Mezzanine, or backport the necessary changes to your local copy. – knbk Jul 26 '16 at 15:23
  • I changed several blocks of code years ago, but don't recognize where exactly they are. I am trying to solve, it's better if I can make it run with less code modification. – Wesley Jul 26 '16 at 23:58

1 Answers1

0

I think you need to change your wsgi.py file as you go for different version of Django.

import os
import sys

from django.core.handlers.wsgi import WSGIHandler

os.environ['DJANGO_SETTINGS_MODULE'] = 'YourAppName.settings'
application = WSGIHandler()

And try to comment all third party application imported in settings.py.

1] ./manage.py runserver will use your wsgi.py however it looks like the stack trace you've shown at the top does not include the wsgi file. Therefore the error is occurring before the wsgi file is loaded.

2] This could well be an issue with your Django settings. For example,may in LOGGING a filename in a non-existent directory.

3] or check this

Community
  • 1
  • 1
Piyush S. Wanare
  • 4,703
  • 6
  • 37
  • 54
  • It doesn't work. Actually, currently I use : from django.core.wsgi import get_wsgi_application application = get_wsgi_application(), either, not work. I don't think it related to wsgi.py since I start the app from mange.py – Wesley Jul 26 '16 at 13:09
  • Try the suggested options hope so any of these will solve your problem. – Piyush S. Wanare Jul 26 '16 at 13:18
  • You definitely need `get_wsgi_application()`, not `WSGIHandler()`, on any modern version of Django. – knbk Jul 26 '16 at 15:02
  • yes, indeed I use get_wsgi_application(), but with the problem till now. I am still trying to solve the issue – Wesley Jul 26 '16 at 23:55