Search code examples
djangoapachewsgibitnamiamazon-lightsail

Apache logs with WSGI ModuleNotFoundError


According to Bitnami's documentation, I've followed their desired steps

  1. Enable WSGI configuration for the Django application
  2. Enable predefined virtual hosts for a Django project
  3. Configure Django project for public access
  4. Create a custom virtual host

In the end of the documentation, it states

You should now be able to browse to your project at http://SERVER-IP/PROJECT/APP.

In this case

SERVER-IP: 35.178.211.120

PROJECT: tutorial

APP: hello_world

If I go to the following locations

I get Internal Error 500. If I check the logs /home/bitnami/stack/apache2/logs

[Tue Sep 29 18:33:16.858668 2020] [wsgi:error] [pid 1473] [remote 109.51.236.49:57609] ModuleNotFoundError: No module named 'PROJECT'


Solution

  • In that specific documentation it says to use similar code to

    import os
    import sys
    sys.path.append('/opt/bitnami/apps/django/django_projects/PROJECT')
    os.environ.setdefault("PYTHON_EGG_CACHE", "/opt/bitnami/apps/django/django_projects/myproject/egg_cache")
    os.environ.setdefault("DJANGO_SETTINGS_MODULE", "PROJECT.settings")
    from django.core.wsgi import get_wsgi_application
    application = get_wsgi_application()
    

    Yet, one can't forget to substitute PROJECT with the name of the Django project. For instance, if your project is named tutorial, then replace PROJECT with tutorial

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

    Then if you go to your instance IP address, like http://35.178.211.120/, you'll see

    Django production ready app