HumBen
HumBen

Reputation: 1

Error running WSGI application, within pythonanywhere

Good day to all,

I was having some issues trying to host my django webapp within pythonanywhere and I keep getting the following errors within the server. Sorry in advance I'm a beginner when it comes to programming

WSGI File:

# +++++++++++ DJANGO +++++++++++
# To use your own Django app use code like this:
import os
import sys

# assuming your Django settings file is at '/home/myusername/mysite/mysite/settings.py'

path = '/home/HumBen/AMC_Inventory/venv/src/src/settings.py'

if path not in sys.path:
    sys.path.insert(0, path)

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

## Uncomment the lines below depending on your Django version
###### then, for Django >=1.5:
from django.core.wsgi import get_wsgi_application
stockmgmt = get_wsgi_application()
###### or, for older Django <=1.4
#import django.core.handlers.wsgi
#application = django.core.handlers.wsgi.WSGIHandler()

Server error:

2021-10-27 22:59:31,228: Error running WSGI application
2021-10-27 22:59:31,233: ModuleNotFoundError: No module named 'src'
2021-10-27 22:59:31,233:   File "/var/www/humben_pythonanywhere_com_wsgi.py", line 16, in <module>
2021-10-27 22:59:31,233:     application = get_wsgi_application()
2021-10-27 22:59:31,233: 
2021-10-27 22:59:31,233:   File "/home/HumBen/AMC_Inventory/venv/lib/python3.9/site-packages/django/core/wsgi.py", line 12, in get_wsgi_application
2021-10-27 22:59:31,233:     django.setup(set_prefix=False)
2021-10-27 22:59:31,233: 
2021-10-27 22:59:31,233:   File "/home/HumBen/AMC_Inventory/venv/lib/python3.9/site-packages/django/__init__.py", line 19, in setup
2021-10-27 22:59:31,234:     configure_logging(settings.LOGGING_CONFIG, settings.LOGGING)
2021-10-27 22:59:31,234: 
2021-10-27 22:59:31,234:   File "/home/HumBen/AMC_Inventory/venv/lib/python3.9/site-packages/django/conf/__init__.py", line 82, in __getattr__
2021-10-27 22:59:31,234:     self._setup(name)
2021-10-27 22:59:31,234: 
2021-10-27 22:59:31,234:   File "/home/HumBen/AMC_Inventory/venv/lib/python3.9/site-packages/django/conf/__init__.py", line 69, in _setup
2021-10-27 22:59:31,235:     self._wrapped = Settings(settings_module)
2021-10-27 22:59:31,235: 
2021-10-27 22:59:31,235:   File "/home/HumBen/AMC_Inventory/venv/lib/python3.9/site-packages/django/conf/__init__.py", line 170, in __init__
2021-10-27 22:59:31,235:     mod = importlib.import_module(self.SETTINGS_MODULE)
2021-10-27 22:59:31,235: ***************************************************

Thank you all in advance, blessings to all!

Upvotes: 0

Views: 166

Answers (1)

caseneuve
caseneuve

Reputation: 476

Assuming that manage.py is in /home/HumBen/AMC_Inventory/venv/src, you should add this path to PYTHONPATH (here: via sys.path.insert call). Then, assuming that settings.py is in /home/HumBen/AMC_Inventory/venv/src/src your current DJANGO_SETTINGS_MODULE config should work. You need to change stockmgmt to application, as well. Also -- remember to edit the wsgi file that is linked to in your Web page on PythonAnywhere and reload the web app.

Upvotes: 0

Related Questions