Django设置导入错误

时间:2015-02-25 13:51:39

标签: python django mod-wsgi

我从RHEL服务器上运行的apache收到导入错误

ImportError: Could not import settings 'FLWeb.settings' (Is it on sys.path? Is there an import error in the settings file?): No module named settings

该应用程序可以在django服务器上正常运行,也适用于CentOS 7机器(使用apache和mod_wsgi)。

我的wsgi.py

import os
import sys

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

os.environ["DJANGO_SETTINGS_MODULE"] = 'FLWeb.settings'

from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()
<。> .conf文件

WSGIScriptAlias / /home/evtdb/FLWeb/FLWeb/wsgi.py

WSGIDaemonProcess localhost python-path=/home/evtdb/FLWeb:/usr/local/lib/python2.7/site-packages
WSGIProcessGroup localhost

<VirtualHost 127.0.0.1:8080>

        <Directory /home/evtdb/FLWeb/FLWeb>
        <Files wsgi.py>
                Order allow,deny
                Allow from all
        </Files>
        </Directory>

</VirtualHost>

我在wsgi.py上尝试了不同的“sys.path”选项来导入设置,但只是不起作用

完整错误日志

[Wed Feb 25 09:22:10 2015] [error] [client 127.0.0.1] mod_wsgi (pid=38788): Target WSGI script '/home/evtdb/FLWeb/FLWeb/wsgi.py' cannot be loaded as Python module.
[Wed Feb 25 09:22:10 2015] [error] [client 127.0.0.1] mod_wsgi (pid=38788): Exception occurred processing WSGI script '/home/evtdb/FLWeb/FLWeb/wsgi.py'.
[Wed Feb 25 09:22:10 2015] [error] [client 127.0.0.1] Traceback (most recent call last):
[Wed Feb 25 09:22:10 2015] [error] [client 127.0.0.1]   File "/home/evtdb/FLWeb/FLWeb/wsgi.py", line 24, in <module>
[Wed Feb 25 09:22:10 2015] [error] [client 127.0.0.1]     application = get_wsgi_application()
[Wed Feb 25 09:22:10 2015] [error] [client 127.0.0.1]   File "/usr/local/lib/python2.7/site-packages/django/core/wsgi.py", line 14, in get_wsgi_application
[Wed Feb 25 09:22:10 2015] [error] [client 127.0.0.1]     django.setup()
[Wed Feb 25 09:22:10 2015] [error] [client 127.0.0.1]   File "/usr/local/lib/python2.7/site-packages/django/__init__.py", line 20, in setup
[Wed Feb 25 09:22:10 2015] [error] [client 127.0.0.1]     configure_logging(settings.LOGGING_CONFIG, settings.LOGGING)
[Wed Feb 25 09:22:10 2015] [error] [client 127.0.0.1]   File "/usr/local/lib/python2.7/site-packages/django/conf/__init__.py", line 46, in __getattr__
[Wed Feb 25 09:22:10 2015] [error] [client 127.0.0.1]     self._setup(name)
[Wed Feb 25 09:22:10 2015] [error] [client 127.0.0.1]   File "/usr/local/lib/python2.7/site-packages/django/conf/__init__.py", line 42, in _setup
[Wed Feb 25 09:22:10 2015] [error] [client 127.0.0.1]     self._wrapped = Settings(settings_module)
[Wed Feb 25 09:22:10 2015] [error] [client 127.0.0.1]   File "/usr/local/lib/python2.7/site-packages/django/conf/__init__.py", line 98, in __init__
[Wed Feb 25 09:22:10 2015] [error] [client 127.0.0.1]     % (self.SETTINGS_MODULE, e)
[Wed Feb 25 09:22:10 2015] [error] [client 127.0.0.1] ImportError: Could not import settings 'FLWeb.settings' (Is it on sys.path? Is there an import error in the settings file?): No module named settings

修改

问题是settings.py权限,我将它们更改为644.现在我收到此错误

[Wed Feb 25 17:23:45 2015] [error] [client 127.0.0.1]   File "/usr/local/lib/python2.7/site-packages/django/apps/registry.py", line 78, in populate
[Wed Feb 25 17:23:45 2015] [error] [client 127.0.0.1]     raise RuntimeError("populate() isn't reentrant")
[Wed Feb 25 17:23:45 2015] [error] [client 127.0.0.1] RuntimeError: populate() isn't reentrant

1 个答案:

答案 0 :(得分:0)

最后问题是关于文件权限。因为我没有得到"(13) Permission Denied":,因为它应该是明显的。

选中此https://wiki.apache.org/httpd/13PermissionDenied

  

类似于unix的系统对httpd.conf中指定的用户或组所拥有的资源的典型权限对于普通文件是644 rw-r-r-,对于目录或CGI脚本是755 drwxr-x-r-x。您可能还需要在支持它们的操作系统上检查扩展权限(例如SELinux权限)。