升级到Django 1.7-AppRegistryNotReady异常 [英] Upgrade to Django 1.7 - AppRegistryNotReady exception

查看:47
本文介绍了升级到Django 1.7-AppRegistryNotReady异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在将Django版本从1.6.7升级到1.7后,我试图通过使一切正常工作而苦苦挣扎.看来我无法专注于正确的事情.到目前为止,我尝试恢复这种情况.

I'm struggling by trying to make things work after upgrading the Django version from 1.6.7 to 1.7. It looks like I'm not able to focus on the right matter. I try to resume the situation so far.

问题是:如果我在wsgi.py文件中保留命令django.setup(),当我尝试访问我的网站时,出现内部服务器错误(500).查看日志,我得到:

Thing is: if I leave the command django.setup() in my wsgi.py file, when I try to access my website I get an internal server error (500). Looking at the logs, I get:

[Sun Oct 12 12:38:50 2014] [error] [client 127.0.0.1] mod_wsgi (pid=23258): Target WSGI script '/home/thrasher/webapps/django/myproject.wsgi' cannot be loaded as Python module.
[Sun Oct 12 12:38:50 2014] [error] [client 127.0.0.1] mod_wsgi (pid=23258): Exception occurred processing WSGI script '/home/thrasher/webapps/django/myproject.wsgi'.
[Sun Oct 12 12:38:50 2014] [error] [client 127.0.0.1] Traceback (most recent call last):
[Sun Oct 12 12:38:50 2014] [error] [client 127.0.0.1]   File "/home/thrasher/webapps/django/myproject.wsgi", line 16, in <module>
[Sun Oct 12 12:38:50 2014] [error] [client 127.0.0.1]     application = get_wsgi_application()
[Sun Oct 12 12:38:50 2014] [error] [client 127.0.0.1]   File "/home/thrasher/webapps/django/lib/python2.7/django/core/wsgi.py", line 14, in get_wsgi_application
[Sun Oct 12 12:38:50 2014] [error] [client 127.0.0.1]     django.setup()
[Sun Oct 12 12:38:50 2014] [error] [client 127.0.0.1]   File "/home/thrasher/webapps/django/lib/python2.7/django/__init__.py", line 21, in setup
[Sun Oct 12 12:38:50 2014] [error] [client 127.0.0.1]     apps.populate(settings.INSTALLED_APPS)
[Sun Oct 12 12:38:50 2014] [error] [client 127.0.0.1]   File "/home/thrasher/webapps/django/lib/python2.7/django/apps/registry.py", line 78, in populate
[Sun Oct 12 12:38:50 2014] [error] [client 127.0.0.1]     raise RuntimeError("populate() isn't reentrant")
[Sun Oct 12 12:38:50 2014] [error] [client 127.0.0.1] RuntimeError: populate() isn't reentrant

但是,如果我评论django.setup()调用,尝试访问该网站将获得此堆栈跟踪:

However, if I comment the django.setup() call, trying to access the website gets me this stack trace:

Environment:


Request Method: GET
Request URL: http://www.creepyvisions.it/

Django Version: 1.7
Python Version: 2.7.8
Installed Applications:
('django.contrib.auth',
 'django.contrib.admin.apps.SimpleAdminConfig',
 'django.contrib.contenttypes',
 'django.contrib.sessions',
 'django.contrib.sites',
 'django.contrib.messages',
 'django.contrib.staticfiles',
 'django.contrib.admin',
 'django.contrib.admindocs',
 'myproject.archivio',
 'sorl.thumbnail',
 'django.contrib.sitemaps',
 'rest_framework')
Installed Middleware:
('django.middleware.common.CommonMiddleware',
 'django.contrib.sessions.middleware.SessionMiddleware',
 'django.middleware.csrf.CsrfViewMiddleware',
 'django.contrib.auth.middleware.AuthenticationMiddleware',
 'django.contrib.messages.middleware.MessageMiddleware')


Traceback:
File "/home/thrasher/webapps/django/lib/python2.7/django/core/handlers/base.py" in get_response
  98.                 resolver_match = resolver.resolve(request.path_info)
File "/home/thrasher/webapps/django/lib/python2.7/django/core/urlresolvers.py" in resolve
  338.             for pattern in self.url_patterns:
File "/home/thrasher/webapps/django/lib/python2.7/django/core/urlresolvers.py" in url_patterns
  367.         patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)
File "/home/thrasher/webapps/django/lib/python2.7/django/core/urlresolvers.py" in urlconf_module
  361.             self._urlconf_module = import_module(self.urlconf_name)
File "/usr/local/lib/python2.7/importlib/__init__.py" in import_module
  37.     __import__(name)
File "/home/thrasher/webapps/django/myproject/urls.py" in <module>
  33.                        url(r'^admin/', include(admin.site.urls)),
File "/home/thrasher/webapps/django/lib/python2.7/django/contrib/admin/sites.py" in urls
  260.         return self.get_urls(), self.app_name, self.name
File "/home/thrasher/webapps/django/lib/python2.7/django/contrib/admin/sites.py" in get_urls
  221.             self.check_dependencies()
File "/home/thrasher/webapps/django/lib/python2.7/django/contrib/admin/sites.py" in check_dependencies
  159.         if not apps.is_installed('django.contrib.admin'):
File "/home/thrasher/webapps/django/lib/python2.7/django/apps/registry.py" in is_installed
  223.         self.check_apps_ready()
File "/home/thrasher/webapps/django/lib/python2.7/django/apps/registry.py" in check_apps_ready
  124.             raise AppRegistryNotReady("Apps aren't loaded yet.")

Exception Type: AppRegistryNotReady at /
Exception Value: Apps aren't loaded yet.

为了完整起见,这是与wsgi相关的代码:

For the sake of completion, this is the code related to wsgi:

myprojext.wsgi

myprojext.wsgi

import os
import sys

os.environ.setdefault("DJANGO_SETTINGS_MODULE", "myproject.settings")

from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()

wgsi.py

import django
from django.core.handlers.wsgi import WSGIHandler


def get_wsgi_application():
    #django.setup()
    return WSGIHandler()

对我来说,事情看起来很奇怪,我在Django官方文档和各种论坛中进行了很多搜索,但仍然无法正常工作.任何建议将不胜感激.

Things look very odd to me, I performed a lot of searches in the official Django docs and in various forums, but I'm still unable to get things work properly. Any suggestions would be much appreciated.

推荐答案

原来,问题是django.contrib.admin在INSTALLED_APPS中重复.看来这是问题的根源.删除第二个引用后,我就在wsgi.py中取消对django.setup()的注释,并且一切都变得晴朗起来了.现在一切正常.

It turned out that the problem was a duplication, in the INSTALLED_APPS, of the django.contrib.admin. It looks that it was the root of the problem. As soon as I removed the second reference, I uncommented django.setup() in wsgi.py and things became sunny and clear again. Now everything is working fine.

这篇关于升级到Django 1.7-AppRegistryNotReady异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆