Search code examples
pythondjangopythonanywhere

Couldnt host Django web to PythonAnywhere


I uploaded my django web to pythonanywhere but everytime when I run the website it will showed Error running WSGI application, ModuleNotFoundError: No module named 'AlertTraceWebsite'. I think I set directory wrongly on the pythonanywhere but doesn't know which steps Im doing it wrong. Any help would be appreciate. thank you.

I have a URL like this (project can be found here):

enter image description here

I configure my pythonanywhere url like this: enter image description here

My pythonanywhere wsgi:


import os
import sys
path = os.path.expanduser('~/kabiboy/atportal')
if path not in sys.path:
    sys.path. insert(0, path)
os.environ['DJANGO_SETTINGS_MODULE'] = 'AlertTraceWebsite.settings'
from django.core.wsgi import get_wsgi_application
from django.contrib.staticfiles.handlers import StaticFilesHandler
application = StaticFilesHandler (get_wsgi_application())

Errors:

2021-10-09 07:27:34,383: Error running WSGI application
2021-10-09 07:27:34,384: ModuleNotFoundError: No module named 'AlertTraceWebsite'
2021-10-09 07:27:34,384:   File "/var/www/kabiboy_pythonanywhere_com_wsgi.py", line 10, in <module>
2021-10-09 07:27:34,384:     application = StaticFilesHandler (get_wsgi_application())
2021-10-09 07:27:34,384: 
2021-10-09 07:27:34,385:   File "/home/kabiboy/.virtualenvs/venv/lib/python3.9/site-packages/django/core/wsgi.py", line 12, in get_wsgi_application
2021-10-09 07:27:34,385:     django.setup(set_prefix=False)
2021-10-09 07:27:34,385: 
2021-10-09 07:27:34,385:   File "/home/kabiboy/.virtualenvs/venv/lib/python3.9/site-packages/django/__init__.py", line 19, in setup
2021-10-09 07:27:34,385:     configure_logging(settings.LOGGING_CONFIG, settings.LOGGING)
2021-10-09 07:27:34,385: 
2021-10-09 07:27:34,385:   File "/home/kabiboy/.virtualenvs/venv/lib/python3.9/site-packages/django/conf/__init__.py", line 82, in __getattr__
2021-10-09 07:27:34,385:     self._setup(name)
2021-10-09 07:27:34,385: 
2021-10-09 07:27:34,385:   File "/home/kabiboy/.virtualenvs/venv/lib/python3.9/site-packages/django/conf/__init__.py", line 69, in _setup
2021-10-09 07:27:34,386:     self._wrapped = Settings(settings_module)
2021-10-09 07:27:34,386: 
2021-10-09 07:27:34,386:   File "/home/kabiboy/.virtualenvs/venv/lib/python3.9/site-packages/django/conf/__init__.py", line 170, in __init__
2021-10-09 07:27:34,386:     mod = importlib.import_module(self.SETTINGS_MODULE)
2021-10-09 07:27:34,386: ***************************************************
2021-10-09 07:27:34,386: If you're seeing an import error and don't know why,
2021-10-09 07:27:34,386: we have a dedicated help page to help you debug: 
2021-10-09 07:27:34,386: https://help.pythonanywhere.com/pages/DebuggingImportError/
2021-10-09 07:27:34,387: ***************************************************

Solution

  • os.path.expanduser('~/kabiboy/atportal') will expand to /home/kabiboy/kabiboy/atportal (mind the doubled kabiboy part) -- that's probably not what you want. If you want to use expanduser with tilde, you should "hide" /home/kabiboy part under the tilde.