Django newbie trying to get treeio to work behind apache
-
22-03-2021 - |
Question
I seem to have similar problem as this guy: Django newbie deployment question - ImportError: Could not import settings 'settings' but i cant make heads or tails of it. The server is running Debian. The app runs fine on internal server, however when trying to use apache + mod_python i get the following problem.
File "/usr/local/lib/python2.6/dist-packages/django/conf/__init__.py", line 89, in __init__
raise ImportError("Could not import settings '%s' (Is it on sys.path?): %s" % (self.SETTINGS_MODULE, e))
ImportError: Could not import settings 'treeio.settings' (Is it on sys.path?): No module named treeio.settings
- Project directory is /var/www/treeio
- All files have file permission 777 (i was testing if there were any permission problems)
Content of httpd.conf
<Location "/treeio/"> SetHandler python-program PythonHandler django.core.handlers.modpython SetEnv DJANGO_SETTINGS_MODULE treeio.settings PythonOption django.root /treeio PythonDebug On PythonPath "['/var/www/treeio'] + sys.path" </Location>
More info:
echo $PYTHONPATH
:/var/www/treeio/..:/var/www/treeio
echo $DJANGO_SETTINGS_MODULE
treeio.settings
>>> import sys
>>> sys.path
['', '/usr/local/lib/python2.6/dist-packages/pip-1.0.2-py2.6.egg', '/var/www/treeio', '/var/www', '/usr/lib/python2.6', '/usr/lib/python2.6/plat-linux2', '/usr/lib/python2.6/lib-tk', '/usr/lib/python2.6/lib-old', '/usr/lib/python2.6/lib-dynload', '/usr/local/lib/python2.6/dist-packages', '/usr/lib/python2.6/dist-packages', '/usr/lib/pymodules/python2.6']
Help me stackoverflow, you're my only hope!
Solution
Your main problem is that you're using mod-python, despite clear warnings that it's deprecated and shouldn't be used for new projects.
But if you really insist on using it, the problem is quite clear: you're adding /var/www/trio
to the path, so everything in trio
needs to be referenced directly - settings
, not trio.settings
.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow