【问题标题】:Deploying Django with WSGI: App Import Error使用 WSGI 部署 Django:应用程序导入错误
【发布时间】:2011-01-20 10:05:25
【问题描述】:

我是 apache、linux 和 python 世界的新手。我正在尝试使用 WSGI(推荐的方式)在 apache 上部署 django 应用程序。

我的django项目目录结构如下...

  • /
  • /apache/django.wsgi
  • /apps/ #我把我所有的应用都放在这个目录下
  • /apps/providers/
  • /apps/shopping/
  • /apps/...
  • /中间件/
  • ...

在 apache 中我有以下设置....

LoadModule wsgi_module modules/mod_wsgi.so
WSGIScriptAlias / D:/Projects/project-name/apache/django.wsgi

<Directory "D:/Projects/project-name/apache/">
  Allow from all
  Order deny,allow
</Directory>

django.wsgi 文件有以下代码...

import os
import sys
import settings

sys.path.append(os.path.dirname(os.path.abspath(__file__)) + '/..')

os.environ['DJANGO_SETTINGS_MODULE'] = 'project_name.settings'

import django.core.handlers.wsgi

application = django.core.handlers.wsgi.WSGIHandler()

在运行时,我在 appache 的 error.log 中发现了这个错误...

  • 此行发生错误。从 apps.providers.models 导入提供者
  • 导入错误:没有名为 providers.models 的模块

我不知道为什么它给了我这个错误。它应该已经从 apps.providers.models 加载了 Provider,但它正在尝试从 providers.model 加载它。

我们将不胜感激任何解决方案。

谢谢

【问题讨论】:

  • 它是否在开发服务器(manage.py runserver)下工作? apps 文件夹中有 init.py 吗?
  • 是的,它正在开发服务器上工作......
  • 我确实有 _ _ init _ _.py 在应用程序文件夹中......

标签: python django apache wsgi


【解决方案1】:

试试这个:

sys.path.insert(0, os.path.join(os.path.abspath(os.path.dirname(__file__)),'..'))

它将您的项目文件夹放在第一个位置,并使用 os.path.join 向上一个目录(这在 Windows 上可能更好)。

您的 python 路径上可能还有另一个“应用程序”模块。

【讨论】:

    猜你喜欢
    • 2019-07-03
    • 1970-01-01
    • 2021-01-21
    • 2012-06-20
    • 1970-01-01
    • 2017-09-17
    • 2012-07-24
    • 1970-01-01
    • 2016-03-30
    相关资源
    最近更新 更多