-2

Link to the youtube video: https://youtu.be/iJrUiem10iI

I have developed a Django application that includes features like downloading YouTube videos (using yt-dlp) and potentially converting file formats.

The Problem:

The application runs perfectly fine on my local machine using python manage.py runserver. I can access the views, for example at http://127.0.0.1:8000/converter/, and the functionality works as expected.

However, after deploying the application to PythonAnywhere (using the free tier), I encounter an error. When I try to access my site at https://kristjan.pythonanywhere.com/ or the specific app URL https://kristjan.pythonanywhere.com/converter/, I get a generic PythonAnywhere error page stating:

Something went wrong :-(

Something went wrong while trying to load this website; please try again later.

Error code: Unhandled Exception

Self-note: The error page provides links to logs, which should contain the specific traceback.

What I've Done and Checked:

Local Server: Confirmed the app works correctly locally via runserver. The URL http://127.0.0.1:8000/converter/ loads the correct index.html template.

Virtual Environment: Created a virtualenv on PythonAnywhere at /home/Kristjan/.virtualenvs/djangoappvirtualenv. I activated this virtualenv and installed all necessary packages (Django, yt-dlp, etc., matching my local environment as closely as possible) using pip install -r requirements.txt (or individually) within a PythonAnywhere console.

Database Setup:

Configured the default DATABASES setting in settings.py to use the standard db.sqlite3 file located within my project directory (/home/Kristjan/djangoapp/db.sqlite3).

Successfully ran python manage.py migrate within a PythonAnywhere console (while the virtualenv was active) to initialize the database schema.

PythonAnywhere Web Tab Configuration: Source Code: Set to /home/Kristjan/djangoapp (where my manage.py and project/app directories are).

Working Directory: Set to /home/Kristjan/. (Could this mismatch with the source code directory be an issue?)

WSGI Configuration File: Path is /var/www/kristjan_pythonanywhere_com_wsgi.py. Contents verified (see below).

Virtualenv: Correctly linked to /home/Kristjan/.virtualenvs/djangoappvirtualenv.

Static Files: Mappings for /static/ and /media/ are configured to point within my /home/Kristjan/djangoapp/ directory structure.

WSGI File (/var/www/kristjan_pythonanywhere_com_wsgi.py):

import os
import sys

# add project directory to the sys.path
project_home = '/home/Kristjan/djangoapp' # Path to directory containing manage.py
if project_home not in sys.path:
    sys.path.insert(0, project_home)

# ensure the project's parent directory is also findable for imports if needed
# sys.path.insert(1, os.path.dirname(project_home)) # Sometimes needed depending on structure

# set environment variable for settings
os.environ['DJANGO_SETTINGS_MODULE'] = 'djangoapp.settings' # Project is named 'djangoapp'

# serve django via WSGI
from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()
Use code with caution.
Python
settings.py (/home/Kristjan/djangoapp/djangoapp/settings.py):

ALLOWED_HOSTS = ['kristjan.pythonanywhere.com']

DEBUG = True (Temporarily, hoping for better errors, but still get the generic page).

INSTALLED_APPS includes my app 'converter'.

DATABASES configured for sqlite3 as mentioned above.

URL Configuration: Confirmed main urls.py includes converter.urls under the /converter/ path, and converter/urls.py defines the paths shown working locally. (Structure details available if needed).

File Structure: Verified the project structure on PythonAnywhere matches my local setup and the standard Django layout.

Reloaded Web App: Clicked the "Reload" button on the PythonAnywhere Web tab multiple times after configuration checks and changes.

Environment:

PythonAnywhere Python: 3.10 (from Web Tab)

Local Django Version: [e.g., 5.1.1 - specify your version]

PythonAnywhere Django Version: [Specify version installed in venv - ensure compatibility]

Question:

What is the problem, How to fix the problem?

Web application URL: Kristijan.pythonanywhere.com

link to the logs: https://drive.google.com/drive/folders/1wg7PKjfU_jiw3U2t_hbK7E75k-OnoqiH?usp=sharing

2 Answers 2

0

The errors are pretty straighforward:

2025-03-29 15:40:15,378: Error running WSGI application
2025-03-29 15:40:15,384: ModuleNotFoundError: No module named 'YouTubeVideoDownloader.settings'

Take a look at kristjan_pythonanywhere_com_wsgi.py file and rename YouTubeVideoDownloader.settings to djangoapp.settings

Sign up to request clarification or add additional context in comments.

3 Comments

that is not the problem, is it already renamed to: os.environ['DJANGO_SETTINGS_MODULE'] = 'djangoapp.settings' You are not correct, it was already like this, this is not the problem. You did not solve the problem.
Ok, I see.. seems like you have a lot of issues besides wsgi (eg missing "kristijan.pythonanywhere.com" in ALLOWED_HOSTS, missing yt_dlp module) Can you please try resolving them first, redeploy and then, if it's still not working - send us the newset error log?
kristijan.pythonanywhere.com is ALREADY inside ALLOWED_HOSTS. It is NOT missing, IT IS THERE. And the logs are already provided. I already provided them, here they are again: drive.google.com/drive/folders/…
0

This is the last error in your error log:

ModuleNotFoundError: No module named 'django' 

You mentioned that you installed Django in your virtualenv, but the error suggests otherwise. I would double-check whether it's installed in the correct virtualenv.

Make sure you hit the "Reload" button on the "Web" page after making changes.

2 Comments

(djangoappvirtualenv) 15:14 ~/djangoapp $ pip install django Looking in links: /usr/share/pip-wheels Requirement already satisfied: django in /home/Kristijan/.virtualenvs/djangoappvirtualenv/lib/python3.10/site-packages (5.2rc1) BUT IT IS THE EXACT SAME VIRTUAL ENVIRONMENT: /home/Kristijan/.virtualenvs/djangoappvirtualenv/ AND I ALREADY CLICKED RELOAD. HERE ARE THE LOGS: drive.google.com/drive/folders/…
Sorry for the late reply! I think you are not looking at the correct part of the error log. The most recent error will be at the end. The last time this particular error occurred was on April 1st, so it looks like your app has a different issue now.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.