【问题标题】:No module names URLs on Django with mod_wsgi?在带有 mod_wsgi 的 Django 中没有名为 URL 的模块?
【发布时间】:2013-06-13 04:35:44
【问题描述】:

我正在尝试在我的 Debian 6 机器上使用 Apache2 mod_wsgi 运行 Django 项目。如果我用开发服务器启动这个项目,这个项目运行良好。但是现在我得到了这个错误:

Exception Type: ImportError at /
Exception Value: No module named urls

我的项目名称是 genalytics。只有一个名为 fileupload 的应用程序。我的 settings.py 上有这个:

ROOT_URLCONF = 'genalytics.urls'

这是我的项目的树结构:

 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

Apache的httpd.conf内容:

Listen 8000

<VirtualHost *:8000>
   ServerName NFS

   DocumentRoot /opt/genalytics


   WSGIScriptAlias / /opt/genalytics/genalytics/wsgi.py
   <Directory /opt/genalytics/genalytics>
      Order allow,deny
      Allow from all
   </Directory>

   Alias /static /opt/genalytics/fileupload/static

</VirtualHost>

wsgi.py 内容:

import os
import sys

sys.path.append('/opt/genalytics')
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "genalytics.settings")
from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()

我正在使用 Django 1.5。谢谢!

【问题讨论】:

  • 您是否为您的应用程序使用任何虚拟环境。
  • 你检查过 apache 日志吗?如果您使用的是 virtualenv,那么在 wsgi 文件中您需要附加 virtualenv 路径。
  • 抱歉,我的意思是说我没有使用 virtualenv。
  • 能否请您显示 apache 日志。
  • 嗨,我的服务器上只有 sudo 访问权限。显然,sudo 用户无法打开 apache2 的日志。我需要成为 root 用户。

标签: django apache2 mod-wsgi


【解决方案1】:

您可能想在wsgi.py 中更改此行:

sys.path.append('/opt/genalytics')

到:

sys.path.insert(0, '/opt/genalytics')

【讨论】:

    猜你喜欢
    • 2012-07-14
    • 2016-06-15
    • 2019-11-13
    • 2016-12-09
    • 2014-05-16
    • 2021-11-17
    • 1970-01-01
    • 1970-01-01
    • 2020-09-25
    相关资源
    最近更新 更多