Django, Settings module not found on YouStable hostings

16 Views Asked by At

I have been deploying django websites on a shared hosting platform (YouStable). With my latest attempt I get a 500 server error page, because it can’t find the settings file.

Background

I did previously manage to deploy a site that worked. I deleted that when I had problems because I had chosen app names that conflict with reserved words and I also discovered I could pip install the Bootstrap web framework (although I need to sort this issue first). I have since had problems creating a new site. I reported a problem when the hosting server was trying to run code from a virtual environment connected to a previous site ( the site and venv have been deleted). The hosting support techies have fixed that.

What I did.

The procedure for deployment involves creating a Python ‘app’ in CPanel's ‘Setup Python app’ by; selecting a Python version (I chose 3.11), choosing a name (‘myapp’), selecting the domain name and saving the app. This creates a virtual environment (or venv) using my username (‘username’), the app name and the Python version. For me:

/home/username/virtualenv/appname/3.11/

CPanel then displays the code to select and activate this venv for use in the terminal section of CPanel. I switched to the terminal, activated the venv, pip installed Django and used django-admin startproject … to create the site (‘mysite’). I then found the wsgi.py file in the project and saved that location in the CPanel Setup Python app

(/mysite/site/wsgi.py)

The CPanel confirms that it CAN find the settings file. Without any further changes this should produce the debug home page (with the rocket on). However I get a 500 server error page and an error log.

The stderr.log error log shows the server going through the same cycle twice, one of which is setout below. For most of a cycle it is using code from the correct venv, but with a couple of exceptions; once where it tries to use imp.py to load a passenger_wsgi.py (which it shouldn't because I've told it where the wsgi.py file is) and once to use importlib.py where it fails to find the settings file. Both times it uses

/opt/alt/python311/lib64/python3.11

instead of my venv and fails.

When I raised a support ticket I was advised to consult my developer (er, that's me). My questions are

Is the swap from my venv to /opt/alt… the cause of the error?

Is there anything more I can do to fix this?

Or do I need to go back to support because it is their problem?

Thanks in advance for any help with this.

The contents of the stderr.log are as follows:

stderr.log (ASCII text)


Traceback (most recent call last):
  File "/home/username/appname/passenger_wsgi.py", line 8, in <module>
    wsgi = imp.load_source('wsgi', 'mysite/mysite/wsgi.py')
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/alt/python311/lib64/python3.11/imp.py", line 172, in load_source
    module = _load(spec)
             ^^^^^^^^^^^
  File "<frozen importlib._bootstrap>", line 721, in _load
  File "<frozen importlib._bootstrap>", line 690, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 940, in exec_module
  File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
  File "mysite/mysite/wsgi.py", line 16, in <module>
    application = get_wsgi_application()
                  ^^^^^^^^^^^^^^^^^^^^^^
  File "/home/username/virtualenv/appname/3.11/lib/python3.11/site-packages/django/core/wsgi.py", line 12, in get_wsgi_application
      django.setup(set_prefix=False)
  File "/home/username/virtualenv/appname/3.11/lib/python3.11/site-packages/django/__init__.py", line 19, in setup
     configure_logging(settings.LOGGING_CONFIG, settings.LOGGING)
                      ^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/username/virtualenv/appname/3.11/lib/python3.11/site-packages/django/conf/__init__.py", line 89, in __getattr__
  self._setup(name)
  File "/home/username/virtualenv/appname/3.11/lib/python3.11/site-packages/django/conf/__init__.py", line 76, in _setup
    self._wrapped = Settings(settings_module)
                    ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/username/virtualenv/appname/3.11/lib/python3.11/site-packages/django/conf/__init__.py", line 190, in __init__
    mod = importlib.import_module(self.SETTINGS_MODULE)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/alt/python311/lib64/python3.11/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<frozen importlib._bootstrap>", line 1204, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1176, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1140, in _find_and_load_unlocked
ModuleNotFoundError: No module named 'mysite.settings'
[UID:1295][2353167] Child process with pid: 2353179 was killed by signal: 15, core dumped: no
0

There are 0 best solutions below