Django从1.4升级到1.8

时间:2015-09-29 17:59:59

标签: python django upgrade

我试图将项目从Django 1.4升级到1.8。我已调整了应用定义as the docs say to

WM / apps.py:

from django.apps import AppConfig

class WMConfig(AppConfig):
    name="wm"
    verbose_name="WebManager"

WM / __ INIT __ PY:

default_app_config = 'wm.apps.WMConfig'

问题是,当我尝试通过浏览器访问应用程序时出现500错误。 Apache日志显示:

 mod_wsgi (pid=33242): Target WSGI script '/home/admusr/project/WebManager/wsgi.py' cannot be loaded as Python module.
 mod_wsgi (pid=33242): Exception occurred processing WSGI script '/home/admusr/project/WebManager/wsgi.py'.
 Traceback (most recent call last):
   File "/home/admusr/project/WebManager/wsgi.py", line 24, in <module>
     application = get_wsgi_application()
   File "/usr/local/lib/python2.7/dist-packages/django/core/wsgi.py", line 14, in get_wsgi_application
     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 85, in populate
     app_config = AppConfig.create(entry)
   File "/usr/local/lib/python2.7/dist-packages/django/apps/config.py", line 112, in create
     mod = import_module(mod_path)
   File "/usr/lib/python2.7/importlib/__init__.py", line 37, in import_module
     __import__(name)
 ImportError: No module named wm.apps

如果我将wm / __ init__.py更改为default_app_config = 'apps.WMConfig',那么它只是说ImportError: No module named apps,因此问题在于它何时尝试加载该模块。我还没有能够通过这样的通用错误消息找到任何相关信息。

1 个答案:

答案 0 :(得分:2)

尝试

default_app_config = 'Webmanager.wm.apps.WMConfig'

另外,the docs建议您直接在INSTALLED_APPS中使用应用配置的路径,而不是在应用的default_app_config

中看到__init__.py
INSTALLED_APPS = (
    ... 
    'Webmanager.wm.apps.WMConfig', 

另一个问题是您的应用配置name属性。这应该是完整路径,即WebManager.wm而不是wm

class WMConfig(AppConfig):
    name="WebManager.wm"
    verbose_name="WebManager"