如何配置WSGI应用以迁移到Django 1.7?

3 投票
1 回答
2555 浏览
提问于 2025-04-19 21:27

我正在尝试把Django从1.6升级到1.7。

当我运行命令python manage.py runserver时,出现了以下错误:

django.core.exceptions.ImproperlyConfigured: WSGI application 'myapp.wsgi.application' could not be loaded; Error importing module: 'cannot import name get_path_info'

这是我settings.py文件中对应的那一行:

WSGI_APPLICATION = 'myapp.wsgi.application'

这是我的wsgi.py文件:

import os

# We defer to a DJANGO_SETTINGS_MODULE already in the environment. This breaks
# if running multiple sites in the same mod_wsgi process. To fix this, use
# mod_wsgi daemon mode with each site in its own daemon process, or use
# os.environ["DJANGO_SETTINGS_MODULE"] = "myapp.settings"
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "myapp.settings")

# This application object is used by any WSGI server configured to use this
# file. This includes Django's development server, if the WSGI_APPLICATION
# setting points here.
from django.core.wsgi import get_wsgi_application

# Apply WSGI middleware here.
# from helloworld.wsgi import HelloWorldApplication
# application = HelloWorldApplication(application)

from dj_static import Cling
application = Cling(get_wsgi_application())

有没有什么办法可以解决这个问题呢?

1 个回答

3

你在用哪个版本的dj_static呢?

我升级到了Django 1.7,结果我的网站坏掉了,这让我想到了你的问题。

我检查了一下我的dj_static版本(我之前用的是0.0.5,发现现在最新的版本是0.0.6)。

在更新dj_static之后,我的网站在Django 1.7下似乎正常运行了。

撰写回答