Forums

Error running WSGI application ModuleNotFoundError: No module named 'myappname.settings'

I am getting this error. The problem is that the message is correct: there is no such module because 'myappname.settings' is renamed 'myappname1.settings'. Unfortunately, WSGI is still looking for this old location. How can I make it look for 'myappname1.settings' instead of 'myappname.settings'?

import os
import sys
path = '/home/somethingfortest1/myappname1'
if path not in sys.path:
    sys.path.append(path)

os.environ['DJANGO_SETTINGS_MODULE'] = 'myappname1.settings'

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

Your code looks correct to me! Two things come to mind:

  • Are you looking at the right error in the error log? The old ones will stay there, and you need to look at the one at the end of the file.
  • Are you editing the right WSGI file? The one you need to change is the one that is linked from the "Web" page inside PythonAnywhere. Django creates its own separate WSGI file, which is a bit confusing because PythonAnywhere doesn't look at that one.