简体   繁体   English

Apache + django pythonpath混淆:ImportError:无法导入设置“ mysite.settings”

[英]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.

相关问题 ImportError:无法导入设置&#39;mysite.settings&#39;(是否在sys.path上?):没有名为mysite.settings的模块 - ImportError: Could not import settings 'mysite.settings' (Is it on sys.path?): No module named mysite.settings ImportError:没有名为mysite.settings的模块(Django) - ImportError: No module named mysite.settings (Django) WSGI / APACHE / DJANGO .. ImportError:无法导入设置 - WSGI / APACHE / DJANGO .. ImportError: Could not import settings Django在apache中与os.environ mysite.settings和settings.py混淆了mod_wsgi - Django in apache with mod_wsgi confused by os.environ mysite.settings and settings.py Django on Apache2(Ubuntu 16.04)报告“没有名为mysite.settings的模块” - Django on Apache2 (Ubuntu 16.04) reports 'No module named mysite.settings' Django ImportError:无法导入设置“ mysite.settings.local”(在sys.path上吗?):没有名为settings.local的模块 - Django ImportError: Could not import settings 'mysite.settings.local' (Is it on sys.path?): No module named settings.local ModuleNotFoundError:没有模块名称“mysite.settings” - ModuleNotFoundError: no module name 'mysite.settings' Apache / mod_wsgi中的Django部署问题。 ImportError:无法导入设置&#39;site.settings&#39; - Django deployment problem in Apache/mod_wsgi. ImportError: Could not import settings 'site.settings' ImportError:无法导入设置 - ImportError: Could not import settings Apache上的Django:设置上的ImportError - Django on Apache: ImportError on settings
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM