[英]Apache+django pythonpath confusion: ImportError: Could not import settings 'mysite.settings'
I use python 2.4 and django 1.2.2 and apache 2.2.3 我使用python 2.4和Django 1.2.2和apache 2.2.3
Write httpd.conf section like this: 像这样编写httpd.conf部分:
<Location "/mysite/">
PythonPath "['/home/usr/www'] + sys.path"
SetHandler python-program
PythonHandler django.core.handlers.modpython
SetEnv DJANGO_SETTINGS_MODULE mysite.settings
PythonOption django.root /mysite
PythonDebug On
</Location>
settings.py path: /home/usr/www/mysite/ settings.py路径:/ home / usr / www / mysite /
but it doesn't work, when i visit http://localhost/mysite/ 但是当我访问http:// localhost / mysite /时它不起作用
ImportError: Could not import settings 'mysite.settings'
ImportError:无法导入设置“ mysite.settings”
i modified it, change /home/usr/www to /var/www and copy settings.py in /var/www it works. 我修改了它,将/ home / usr / www更改为/ var / www,然后在/ var / www中复制settings.py。 So why apache treat two directories differently?
那么,为什么apache对待两个目录的区别呢?
Are you using SELinux? 您正在使用SELinux吗? Compare the output of
比较输出
ls -laZ /var/www
and 和
ls -laZ /home/usr/www
Chances are that your home directory cannot be accessed by the apache process. 可能是您的主目录无法被apache进程访问。 If this is the problem, it might be solved as simply as
如果这是问题,则可以像解决问题一样简单
chcon -R --reference=/var/www /home/usr/www
chmod og+x /home/usr /home/usr/www
BTW: http://docs.djangoproject.com/en/dev/howto/deployment/modpython/ warns that "Support for mod_python will be deprecated in a future release of Django. If you are configuring a new deployment, you are strongly encouraged to consider using mod_wsgi or any of the other supported backends." 顺便说一句: http : //docs.djangoproject.com/en/dev/howto/deployment/modpython/警告:“在将来的Django版本中将不再支持mod_python。如果要配置新的部署,强烈建议您考虑使用mod_wsgi或任何其他受支持的后端。”
添加PythonPath "['/home/usr/www/mysite'] + sys.path"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.