gpt4 book ai didi

django - mod_python 错误 : ImportError: Could not import settings

转载 作者:行者123 更新时间:2023-12-04 13:35:47 26 4
gpt4 key购买 nike

试图让 Django 与 Apache 一起工作,但出现以下错误:

ImportError: Could not import settings 'MyDjangoApp.settings' (Is it on sys.path? Does it have syntax errors?): No module named MyDjangoApp.settings



我的 Django 应用程序位于/home/user/django/MyDjangoApp/

我的 httpd.conf 位置部分如下所示:
<Location "/MyDjangoApp/">
SetHandler python-program
PythonHandler django.core.handlers.modpython
SetEnv DJANGO_SETTINGS_MODULE MKSearch.settings
PythonOption django.root /MyDjangoApp
PythonPath "['/home/user/django/MyDjangoApp/','/var/www'] + sys.path"
PythonDebug On
</Location>

请告诉我如何更正位置部分以使 Django 工作?

最佳答案

我认为 mod_python 正在寻找/home/user/django/MyDjangoApp 目录中不存在的 MKSearch 模块中的设置。尝试将父目录添加到 PythonPath 指令,如下所示:

<Location "/MyDjangoApp/">
SetHandler python-program
PythonHandler django.core.handlers.modpython
SetEnv DJANGO_SETTINGS_MODULE MKSearch.settings
PythonOption django.root /MyDjangoApp
PythonPath "['/home/user/django/', '/home/user/django/MyDjangoApp,'/var/www'] + sys.path"
PythonDebug On
</Location>

或者从 DJANGO_SETTINGS_MODULE 环境变量中删除模块名称,如下所示:
<Location "/MyDjangoApp/">
SetHandler python-program
PythonHandler django.core.handlers.modpython
SetEnv DJANGO_SETTINGS_MODULE settings
PythonOption django.root /MyDjangoApp
PythonPath "['/home/user/django/MyDjangoApp,'/var/www'] + sys.path"
PythonDebug On
</Location>

关于django - mod_python 错误 : ImportError: Could not import settings,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/962533/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com