0

I know this question has been asked quite a lot but all the solutions given do not seem to fit for me.

I run this in a venv with python 3.6.8 and django 2.2.10 When I run django from cli it works and all functionality is working great so I know it is not django itself that is failing me.

Path to wsgi script is "/opt/sites/aws/okta/wsgi.py"

Actual 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()

When running python to see what errors it gives I get

ModuleNotFoundError: No module named 'okta.settings'

I get the same error when running apache with debug logging.

I have quadruple checked the path and the environment variables and they are set right in the wsgi.py script.

Asked for the 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
rottdogg
  • 11
  • 5
  • Can you share your INSTALLED_APPS in settings.py? We also need your path folder structure from your project – Danizavtz Dec 23 '20 at 20:34
  • did you create `okta` app folder in django according to error it is saying that you do not have that `okta` folder with `settings.py` file or did not registered app correctly – Chandan Dec 23 '20 at 20:38
  • Added the INSTALLED_APPS section to the question. Yes, this was working for months prior to this without issue under the same structure. – rottdogg Dec 23 '20 at 20:49

1 Answers1

1

Although I did not figure out what was wrong. This is what I did to resolve.

Note for anyone reading this in the future, please DO NOT do this first. I tried other more common results like ImportError: No module named mysite.settings (Django) to fix the issue first and when none worked I tried this.

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

voila it works without issue, no config change at all. Very strange but I'll take a working production site then a broken one.

rottdogg
  • 11
  • 5