简体   繁体   English

ImportError - Django和mod_wsgi

[英]ImportError - Django and mod_wsgi

I'm attempting to set up mod_wsgi with Django and Apache locally on a Fedora 16 machine. 我正试图在Fedora 16机器上本地设置mod_wsgi与Django和Apache。 I run into the error: 我遇到了错误:

ImportError: Could not import settings 'cat.settings' (Is it on sys.path?): No module named cat.settings

I realize there are a few other questions about this - but their solutions have not fixed this error. 我意识到还有一些其他问题 - 但他们的解决方案并没有解决这个错误。 I appreciate any help or ideas you may have regarding the message! 我感谢您对此消息的任何帮助或想法!

-- -

Here's a bit of insight into my set-up: 以下是对我的设置的一些了解:

  • Receiving 500 Internal Server Error at localhost. 在localhost接收500内部服务器错误。
  • My directory is: /home/name/src/django/animals/cat (where the cat directory contains an __init__.py and a settings.py file. 我的目录是:/ home / name / src / django / animals / cat(其中cat目录包含__init__.py和settings.py文件。
  • I have one application folder in the cat directory, named catOne - it also contains an __init__.py file. 我在cat目录中有一个名为catOne的应用程序文件夹 - 它还包含一个__init__.py文件。
  • My wsgi file looks like this: 我的wsgi文件如下所示:

import os
import sys

sys.path.append('/home/name/src/django/animals/cat')
sys.path.append('/home/name/src/django/animals')

sys.stderr.write('\n'.join(sys.path))

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

packages = os.path.join(root, 'environ/lib/python2.7/site-packages')
sys.path.insert(0, packages)

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

import django.core.handlers.wsgi
application = django.core.handlers.wsgi.WSGIHandler()
  • The permissions on the settings and init files are 755, but I've also tried 777 without success. 设置和初始化文件的权限是755,但我也尝试了777没有成功。

  • My sys.path looks like: 我的sys.path看起来像:


/var/www
/usr/lib/python27.zip
/usr/lib/python2.7
/usr/lib/python2.7/plat-linux2
/usr/lib/python2.7/lib-tk
/usr/lib/python2.7/lib-old
/usr/lib/python2.7/lib-dynload
/usr/lib/python2.7/site-packages
/usr/lib/python2.7/site-packages/PIL
/usr/lib/python2.7/site-packages/gst-0.10
/usr/lib/python2.7/site-packages/gtk-2.0
/usr/lib/python2.7/site-packages/setuptools-0.6c11-py2.7.egg-info
/home/name/src/django/animals/cat
/home/name/src/django/animals

Thanks again for your help! 再次感谢你的帮助!

SELinux was causing an issue accessing the file. SELinux导致访问该文件的问题。 This probably isn't the best way, but I disabled it entirely by editing the /etc/selinux/config file. 这可能不是最好的方法,但我通过编辑/ etc / selinux / config文件完全禁用它。 Change SELINUX=enforcing to SELINUX=disabled. 更改SELINUX =强制执行SELINUX =禁用。

Again, there are probably finer grain controls for changing SELinux so disable at your own peril. 再次,可能有更精细的谷物控制来改变SELinux所以禁用你自己的危险。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM