没有名为 'mysite.settings' 的模块

No module named 'mysite.settings'

我知道这个问题已经被问了很多,但是给出的所有解决方案似乎都不适合我。

我 运行 这是在 python 3.6.8 和 django 2.2.10 的 venv 中 当我从 cli 运行 django 工作时,所有功能都运行良好,所以我知道不是 django 本身让我失望。

wsgi 脚本的路径是“/opt/sites/aws/okta/wsgi.py”

实际wsgi.py:

import os, sys
sys.path.append('/opt/sites/aws')
#path = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
#sys.path.append(path)
print(sys.path)

os.environ.setdefault("DJANGO_SETTINGS_MODULE", "okta.settings")

from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()

当 运行ning python 查看它给出的错误时

ModuleNotFoundError: No module named 'okta.settings'

在使用调试日志记录 运行ning apache 时,我遇到了同样的错误。

我已经四次检查了路径和环境变量,它们在 wsgi.py 脚本中设置正确。

要求 INSTALLED_APPS

INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'okta_oauth2.apps.OktaOauth2Config',
    'ops.apps.OpsConfig'
]

aws/
    bin/
    lib/
    lib64/
    logs/
    okta/
        __init__.py
        urls.py
        settings.py
        wsgi.py
    okta_oauth2/
    ops/
    share/
    static/
    manage.py
    pyvenv.cfg

虽然没弄明白哪里不对。这就是我所做的解决。

请注意以后阅读本文的任何人,请不要先这样做。我尝试了其他更常见的结果,如 首先解决问题,当 none 起作用时,我尝试了这个。

cd /opt/sites #Just outside the venv
sudo service httpd stop # stop web server
mv aws aws_broken_20201223 # move your broken env to a new name but do not delete
python3 -m venv aws #create new venv 
cp -R aws_broken_20201223/(django dirs) aws/ #copy all the custom apps and project you have to the new folder
cd aws #go to the new install
bin/activate #activate your env
pip 3 install -r requirements.txt # I had a predefined requirements.txt for all mods I needed. I would suggest you do the same before doing this. 
python3 okta/wsgi.py # Test to see if you are still getting the not found error 
sudo service httpd start # start web server back up

瞧,它工作没有问题,根本没有配置更改。很奇怪,但我会选择一个工作的生产站点,然后是一个损坏的站点。