简体   繁体   中英

Django settings import error

I'm getting an import error from apache running on RHEL server

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

The app run properly with django server and also works on a CentOS 7 machine (with apache and mod_wsgi).

my 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()

the .conf file

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>

I've tried different "sys.path" options on wsgi.py to import settings but just doesnt work

full error log

[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

EDIT

Problem was settings.py permissions, i changed them to 644. Now i got this error

[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

Finally the problem was about file permissions. As I didnt got a "(13) Permission Denied": wasnt as evident as it should be.

Check this https://wiki.apache.org/httpd/13PermissionDenied

Typical permissions on a unix-like system for resources not owned by the User or Group specified in httpd.conf would be 644 rw-r--r- for ordinary files and 755 drwxr-xrx for directories or CGI scripts. You may also need to check extended permissions (such as SELinux permissions) on operating systems that support them.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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