如何在本地运行OpenShift Django项目?

2 投票
2 回答
1077 浏览
提问于 2025-04-18 01:25

我正在尝试在本地运行我的django 1.6项目(是从openshift下载的),我用的命令是:

$python3.3 manage.py runserver

但是出现了错误:

Unhandled exception in thread started by <function check_errors.<locals>.wrapper at 0xb691592c>
Traceback (most recent call last):
  File "/usr/local/lib/python3.3/dist-packages/Django-1.6-py3.3.egg/django/utils/module_loading.py", line 21, in import_by_path
    module = import_module(module_path)
  File "/usr/lib/python3.3/importlib/__init__.py", line 90, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1584, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1565, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1529, in _find_and_load_unlocked
ImportError: No module named 'wsgi'

During handling of the above exception, another exception occurred:

............................................................
..........................................................
...................................................
  File "<frozen importlib._bootstrap>", line 1584, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1565, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1529, in _find_and_load_unlocked
django.core.exceptions.ImproperlyConfigured: WSGI application 'wsgi.application' could not be loaded; Error importing module wsgi: "No module named 'wsgi'"

不过在openshift.com上这个项目可以正常运行。我该怎么在本地运行它,以便快速调试呢?

2 个回答

0

在一个应用程序的结构和标准示例类似的情况下,我需要做以下更改:

在manage.py文件中:

# Add the root to the path to support local testing with
# runserver / WSGI_APPLICATION
sys.path.append(os.path.join(os.path.dirname(__file__), '..','..'))

在settings.py文件中:

WSGI_APPLICATION = 'wsgi.application.application'

我认为WSGI_APPLICATION这个变量只在运行服务器时用到,所以它不会影响已经部署的应用程序。

5

虽然我来得有点晚,但我也遇到过同样的问题,找到了一个替代的解决办法。

我在

sys.path.append(os.path.join(os.path.dirname(__file__), '..', ".."))

这个文件里添加了内容,

然后在

mysite/wsgi.py文件里加了一个else语句。

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

撰写回答