使用mod_wsgi的django部署中没有名为middleware的模块



我使用的是Django 1.5。我的mod_wsgi文件如下所示。

import os
import sys
sys.path.append('/opt/genalytics')
# 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"] = "genalytics.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
application = get_wsgi_application()

我看到500内部服务器错误。日志文件中的错误:

[Tue Jun 18 16:06:35 2013] [error] [client 172.16.0.163]   File "/usr/local/lib/python2.6/dist-packages/django/core/handlers/base.py", line 53, in load_middleware
[Tue Jun 18 16:06:35 2013] [error] [client 172.16.0.163]     raise exceptions.ImproperlyConfigured('Error importing middleware %s: "%s"' % (mw_module, e))
[Tue Jun 18 16:06:35 2013] [error] [client 172.16.0.163] ImproperlyConfigured: Error importing middleware fileupload.middleware: "No module named middleware"
[Tue Jun 18 16:06:36 2013] [error] [client 172.16.0.163] mod_wsgi (pid=26321): Exception occurred processing WSGI script '/opt/genalytics/genalytics/wsgi.py'.
[Tue Jun 18 16:06:36 2013] [error] [client 172.16.0.163] Traceback (most recent call last):
[Tue Jun 18 16:06:36 2013] [error] [client 172.16.0.163]   File "/usr/local/lib/python2.6/dist-packages/django/core/handlers/wsgi.py", line 236, in __call__
[Tue Jun 18 16:06:36 2013] [error] [client 172.16.0.163]     self.load_middleware()
[Tue Jun 18 16:06:36 2013] [error] [client 172.16.0.163]   File "/usr/local/lib/python2.6/dist-packages/django/core/handlers/base.py", line 53, in load_middleware
[Tue Jun 18 16:06:36 2013] [error] [client 172.16.0.163]     raise exceptions.ImproperlyConfigured('Error importing middleware %s: "%s"' % (mw_module, e))
[Tue Jun 18 16:06:36 2013] [error] [client 172.16.0.163] ImproperlyConfigured: Error importing middleware fileupload.middleware: "No module named middleware"

结构:

/opt/
   genalytics
     fileupload
     genalytics
     manage.py

项目名称是genalytics。应用程序名称为fileupload

全树结构:

opt/
  genalytics/
    ├── fileupload
    │   ├── backend.py
    │   ├── backend.pyc
    │   ├── backends.py
    │   ├── backends.pyc
    │   ├── django.wsgi
    │   ├── encrypt.py
    │   ├── encrypt.pyc
    │   ├── forms.py
    │   ├── forms.pyc
    │   ├── functions.py
    │   ├── functions.pyc
    │   ├── __init__.py
    │   ├── __init__.pyc
    │   ├── middleware.py
    │   ├── middleware.pyc
    │   ├── models.py
    │   ├── models.pyc
    │   ├── static
    │   │   ├── admin
    │   │   │   ├── css
    │   │   │   │   ├── base.css
    │   │   │   │   ├── changelists.css
    │   │   │   │   ├── dashboard.css
    │   │   │   │   ├── forms.css
    │   │   │   │   ├── ie.css
    │   │   │   │   ├── login.css
    │   │   │   │   ├── rtl.css
    │   │   │   │   └── widgets.css
    │   │   │   ├── img
    │   │   │   │   ├── changelist-bg.gif
    │   │   │   │   ├── changelist-bg_rtl.gif
    │   │   │   │   ├── chooser-bg.gif
    │   │   │   │   ├── tool-right.gif
    │   │   │   │   ├── tool-right_over.gif
    │   │   │   │   ├── tooltag-add.gif
    │   │   │   │   ├── tooltag-add_over.gif
    │   │   │   │   ├── tooltag-arrowright.gif
    │   │   │   │   └── tooltag-arrowright_over.gif
    │   │   │   └── js
    │   │   │       ├── actions.js
    │   │   │       ├── actions.min.js
    │   │   │       ├── admin
    │   │   │       │   ├── DateTimeShortcuts.js
    │   │   │       │   ├── ordering.js
    │   │   │       │   └── RelatedObjectLookups.js
    │   │   │       ├── calendar.js
    │   │   │       ├── collapse.js
    │   │   │       └── urlify.js
    │   │   ├── css
    │   │   │   ├── datepicker.css
    │   │   │   ├── datePicker.css
    │   │   │   ├── jquery-ui.css~
    │   │   │   ├── pro_dropline.css
    │   │   │   ├── pro_dropline_ie.css
    │   │   │   ├── screen.css
    │   │   │   └── screen.css~
    │   │   ├── endless_pagination
    │   │   │   └── js
    │   │   │       ├── endless.js
    │   │   │       ├── endless_on_scroll.js
    │   │   │       └── endless-pagination.js
    │   │   │   ├── transfer.png
    │   │   │   ├── ui-icons_454545_256x240.png
    │   │   │   ├── upload.png
    │   │   │   └── up.png
    │   │   ├── js
    │   │   │   ├── endless-pagination.js
    │   │   │   ├── jquery
    │   │   │   │   ├── Copy of custom_jquery.js
    │   │   │   │   ├── custom_jquery.js
    │   │   │   │   ├── date.js
    │   │   │   │   ├── jquery-1.4.1.min.js
    │   │   │   │   ├── jquery.bind.js
    │   │   │   │   ├── jquery.datePicker.js
    │   │   │   │   ├── jquery.dimensions.js
    │   │   │   │   ├── jquery.filestyle.js
    │   │   │   │   ├── jquery.pngFix.pack.js
    │   │   │   │   ├── jquery.selectbox-0.5.js
    │   │   │   │   ├── jquery.selectbox-0.5_style_2.js
    │   │   │   │   ├── jquery.selectbox-0.5_style_3.js
    │   │   │   │   ├── jquery.tablesorter.js
    │   │   │   │   ├── jquery.tooltip.js
    │   │   │   │   ├── jquery.usermode.js
    │   │   │   │   ├── ui.checkbox.js
    │   │   │   │   └── ui.core.js
    │   │   │   ├── jquery-1.9.1.js
    │   │   │   ├── jquery.js
    │   │   │   ├── jquery-latest.js
    │   │   │   ├── jquery.pajinate.js
    │   │   │   ├── jquery.tablesorter.js
    │   │   │   ├── jquery-ui-1.10.3.custom.min.js
    │   │   │   ├── test.js~
    │   │   │   └── transfer.js
    │   │   ├── login.css
    │   │   ├── PIE.htc
    │   │   ├── style.css
    │   │   └── style.css~
    │   ├── svn-commit.tmp
    │   ├── tasks.py
    │   ├── tasks.py~
    │   ├── tasks.pyc
    │   ├── templates
    │   │   ├── ajax.html
    │   │   ├── base.html
    │   │   ├── create_session.html
    │   │   ├── create_session.html~
    │   │   ├── deleted_files.html
    │   │   ├── edit_session.html
    │   │   ├── file_info.html
    │   │   ├── footer.html
    │   │   ├── forgot_password.html
    │   │   ├── form.html
    │   │   ├── header.html
    │   │   ├── list_files.html
    │   │   ├── list_session.html
    │   │   ├── list_session.html~
    │   │   ├── login_backend.html
    │   │   ├── message_forgot.html
    │   │   ├── nav.html
    │   │   ├── new_password.html
    │   │   ├── notify.html
    │   │   ├── overview.html
    │   │   ├── overview.html~
    │   │   ├── password_successful.html
    │   │   ├── reform.html
    │   │   ├── registration
    │   │   │   ├── password_reset_complete.html
    │   │   │   ├── password_reset_confirm.html
    │   │   │   ├── password_reset_done.html
    │   │   │   ├── password_reset_email.html
    │   │   │   └── password_reset_form.html
    │   │   ├── right.html
    │   │   ├── search_result.html
    │   │   ├── shared_by_me.html
    │   │   ├── shared_with_me.html
    │   │   ├── style.css
    │   │   ├── synced.html
    │   │   ├── test.html
    │   │   ├── test.html~
    │   │   ├── thanks.html
    │   │   ├── uploaded_files.html
    │   │   ├── uploaded_files.html~
    │   │   └── uploaded_notify.html
    │   ├── tests.py
    │   ├── views.py
    │   ├── views.py~
    │   └── views.pyc
    ├── genalytics
    │   ├── __init__.py
    │   ├── __init__.pyc
    │   ├── settings.py
    │   ├── settings.py~
    │   ├── settings.pyc
    │   ├── urls.py
    │   ├── urls.pyc
    │   ├── wsgi.py
    │   ├── wsgi.py~
    │   └── wsgi.pyc
    └── manage.py

如何在/opt目录中出现两次generalytics ?

无论如何,您可能需要:

sys.path.append('/opt')

,否则Python将无法找到文件上传包。


更新

现在您已经修复了问题中的目录结构,下一个问题是目录是否可访问,文件是否对Apache运行的用户可读?

换句话说,Apache不能以你的身份运行,所以目录/文件必须能被其他人读懂。

最新更新