admin管理员组

文章数量:1356262

Link to the youtube video:

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 / or the specific app URL /, 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']

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

link to the logs:

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/ or the specific app URL https://kristjan.pythonanywhere/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']

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

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

Share Improve this question asked Mar 29 at 21:13 ChristianChristian 11
Add a comment  | 

2 Answers 2

Reset to default 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

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.

本文标签: