Thank you, Glenn. I had already tried that, but it still does not work...
I have:
- created a .env file inside Blog/app/
- deleted the previous .venv folder and created one with "mkvirtualenv venv"
- launched workon venv
- installed all the libraries in the requirements.txt
- moved venv inside .virtualenvs with mv venv ~/.virtualenvs/venv
- tested echo $SECRET_KEY (it works)
This is the wsgi.py file:
import os
import sys
from dotenv import load_dotenv
from django.core.wsgi import get_wsgi_application
# Adjust this path to your project directory
path = '/home/SirJude/Blog'
if path not in sys.path:
sys.path.insert(0, path)
# Path to the folder containing the .env file
env_folder = os.path.expanduser('/home/SirJude/Blog/app')
# Load environment variables from the .env file
load_dotenv(os.path.join(env_folder, '.env'))
# Set the default Django settings module
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "app.settings")
# Get the WSGI application
application = get_wsgi_application()
- I launched the command:
echo 'set -a; source /home/SirJude/Blog/app/.env; set +a' >> ~/.virtualenvs/venv/bin/postactivate
Finally:
- I corrected the path to the virtual environment in the tab web:
Virtualenv:
Use a virtualenv to get different versions of flask,
django etc from our default system ones. More info here. You need to
Reload your web app to activate it; NB - will do nothing if the
virtualenv does not exist.
/home/SirJude/.virtualenvs/venv
- I reloded the application.
...but I still get the same message:
2024-10-08 18:16:59,817: Invalid HTTP_HOST header: 'sirjude.pythonanywhere.com'. You may need to add 'sirjude.pythonanywhere.com' to ALLOWED_HOSTS.
Traceback (most recent call last):
File "/home/SirJude/.virtualenvs/venv/lib/python3.10/site-packages/django/core/handlers/exception.py", line 55, in inner
response = get_response(request)
File "/home/SirJude/.virtualenvs/venv/lib/python3.10/site-packages/django/utils/deprecation.py", line 133, in __call__
response = self.process_request(request)
File "/home/SirJude/.virtualenvs/venv/lib/python3.10/site-packages/django/middleware/common.py", line 48, in process_request
host = request.get_host()
File "/home/SirJude/.virtualenvs/venv/lib/python3.10/site-packages/django/http/request.py", line 151, in get_host
raise DisallowedHost(msg)
django.core.exceptions.DisallowedHost: Invalid HTTP_HOST header: 'sirjude.pythonanywhere.com'. You may need to add 'sirjude.pythonanywhere.com' to ALLOWED_HOSTS.
2024-10-08 18:16:59,971: Error running WSGI application
2024-10-08 18:16:59,971: django.core.exceptions.ImproperlyConfigured: The SECRET_KEY setting must not be empty.
2024-10-08 18:16:59,972: File "/home/SirJude/.virtualenvs/venv/lib/python3.10/site-packages/django/core/handlers/wsgi.py", line 124, in __call__
2024-10-08 18:16:59,972: response = self.get_response(request)
2024-10-08 18:16:59,972:
2024-10-08 18:16:59,972: File "/home/SirJude/.virtualenvs/venv/lib/python3.10/site-packages/django/core/handlers/base.py", line 140, in get_response
2024-10-08 18:16:59,972: response = self._middleware_chain(request)
2024-10-08 18:16:59,972:
2024-10-08 18:16:59,972: File "/home/SirJude/.virtualenvs/venv/lib/python3.10/site-packages/django/core/handlers/exception.py", line 57, in inner
2024-10-08 18:16:59,972: response = response_for_exception(request, exc)
2024-10-08 18:16:59,973:
2024-10-08 18:16:59,973: File "/home/SirJude/.virtualenvs/venv/lib/python3.10/site-packages/django/core/handlers/exception.py", line 140, in response_for_exception
2024-10-08 18:16:59,973: response = handle_uncaught_exception(
2024-10-08 18:16:59,973:
2024-10-08 18:16:59,973: File "/home/SirJude/.virtualenvs/venv/lib/python3.10/site-packages/django/core/handlers/exception.py", line 181, in handle_uncaught_exception
2024-10-08 18:16:59,973: return debug.technical_500_response(request, *exc_info)
2024-10-08 18:16:59,974:
2024-10-08 18:16:59,974: File "/home/SirJude/.virtualenvs/venv/lib/python3.10/site-packages/django/views/debug.py", line 69, in technical_500_response
2024-10-08 18:16:59,974: html = reporter.get_traceback_html()
2024-10-08 18:16:59,974:
2024-10-08 18:16:59,974: File "/home/SirJude/.virtualenvs/venv/lib/python3.10/site-packages/django/views/debug.py", line 428, in get_traceback_html
2024-10-08 18:16:59,974: c = Context(self.get_traceback_data(), use_l10n=False)
2024-10-08 18:16:59,974:
2024-10-08 18:16:59,974: File "/home/SirJude/.virtualenvs/venv/lib/python3.10/site-packages/django/views/debug.py", line 397, in get_traceback_data
2024-10-08 18:16:59,975: "settings": self.filter.get_safe_settings(),
2024-10-08 18:16:59,975:
2024-10-08 18:16:59,975: File "/home/SirJude/.virtualenvs/venv/lib/python3.10/site-packages/django/views/debug.py", line 156, in get_safe_settings
2024-10-08 18:16:59,975: settings_dict[k] = self.cleanse_setting(k, getattr(settings, k))
2024-10-08 18:16:59,975:
2024-10-08 18:16:59,975: File "/home/SirJude/.virtualenvs/venv/lib/python3.10/site-packages/django/conf/__init__.py", line 98, in __getattr__
2024-10-08 18:16:59,975: raise ImproperlyConfigured("The SECRET_KEY setting must not be empty.")