For me it does not work...
This is my wsgi.py file:
"""
WSGI config for app project.
It exposes the WSGI callable as a module-level variable named application
.
For more information on this file, see
https://docs.djangoproject.com/en/5.1/howto/deployment/wsgi/
"""
import os
import sys
from django.core.wsgi import get_wsgi_application
path = '/home/SirJude/Blog/app'
if path not in sys.path:
sys.path.insert(0, path)
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "app.settings")
application = get_wsgi_application()
And this is my settings:
"""
Django settings for app project.
Generated by 'django-admin startproject' using Django 5.1.1.
For more information on this file, see
https://docs.djangoproject.com/en/5.1/topics/settings/
For the full list of settings and their values, see
https://docs.djangoproject.com/en/5.1/ref/settings/
"""
from dotenv import load_dotenv
from pathlib import Path
import logging
import os
import sys
load_dotenv()
# Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = Path(__file__).resolve().parent.parent
# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/5.1/howto/deployment/checklist/
SECRET_KEY = os.getenv("SECRET_KEY")
Logger = logging.getLogger(__name__)
Logger.error(Path.cwd())
IS_PRODUCTION = os.getenv('DJANGO_PRODUCTION', 'False') == 'True'
Logger.error(f"IS_PRODUCTION: {IS_PRODUCTION}")
if IS_PRODUCTION:
DEBUG = False
ALLOWED_HOSTS = ['sirjude.pythonanywhere.com']
Logger.error(f"ALLOWED_HOSTS: {ALLOWED_HOSTS}")
# # Security settings for production
# SECURE_HSTS_SECONDS = 31536000 # 1 year
# SECURE_HSTS_INCLUDE_SUBDOMAINS = True
# SECURE_HSTS_PRELOAD = True
SECURE_SSL_REDIRECT = True
SESSION_COOKIE_SECURE = True
CSRF_COOKIE_SECURE = True
else:
DEBUG = True
ALLOWED_HOSTS = ['localhost', '127.0.0.1']
I keep receiving the same error:
2024-10-08 13:19:14,906: 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/Blog/.venv/lib/python3.10/site-packages/django/core/handlers/exception.py", line 55, in inner
response = get_response(request)
File "/home/SirJude/Blog/.venv/lib/python3.10/site-packages/django/utils/deprecation.py", line 133, in __call__
response = self.process_request(request)
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 13:19:15,151: Error running WSGI application
2024-10-08 13:19:15,152: django.core.exceptions.ImproperlyConfigured: The SECRET_KEY setting must not be empty.
2024-10-08 13:19:15,152: File "/home/SirJude/Blog/.venv/lib/python3.10/site-packages/django/core/handlers/wsgi.py", line 124, in __call__
2024-10-08 13:19:15,153: response = self.get_response(request)
2024-10-08 13:19:15,153:
2024-10-08 13:19:15,153: File "/home/SirJude/Blog/.venv/lib/python3.10/site-packages/django/core/handlers/base.py", line 140, in get_response
2024-10-08 13:19:15,153: response = self._middleware_chain(request)
2024-10-08 13:19:15,153:
2024-10-08 13:19:15,153: File "/home/SirJude/Blog/.venv/lib/python3.10/site-packages/django/core/handlers/exception.py", line 57, in inner
2024-10-08 13:19:15,154: response = response_for_exception(request, exc)
2024-10-08 13:19:15,154:
2024-10-08 13:19:15,154: File "/home/SirJude/Blog/.venv/lib/python3.10/site-packages/django/core/handlers/exception.py", line 140, in response_for_exception
2024-10-08 13:19:15,154: response = handle_uncaught_exception(
2024-10-08 13:19:15,154:
2024-10-08 13:19:15,155: File "/home/SirJude/Blog/.venv/lib/python3.10/site-packages/django/core/handlers/exception.py", line 181, in handle_uncaught_exception
2024-10-08 13:19:15,155: return debug.technical_500_response(request, *exc_info)
2024-10-08 13:19:15,155:
2024-10-08 13:19:15,155: File "/home/SirJude/Blog/.venv/lib/python3.10/site-packages/django/views/debug.py", line 69, in technical_500_response
2024-10-08 13:19:15,156: html = reporter.get_traceback_html()
2024-10-08 13:19:15,156:
2024-10-08 13:19:15,156: File "/home/SirJude/Blog/.venv/lib/python3.10/site-packages/django/views/debug.py", line 428, in get_traceback_html
2024-10-08 13:19:15,156: c = Context(self.get_traceback_data(), use_l10n=False)
2024-10-08 13:19:15,156:
2024-10-08 13:19:15,156: File "/home/SirJude/Blog/.venv/lib/python3.10/site-packages/django/views/debug.py", line 397, in get_traceback_data
2024-10-08 13:19:15,156: "settings": self.filter.get_safe_settings(),
2024-10-08 13:19:15,156:
2024-10-08 13:19:15,156: File "/home/SirJude/Blog/.venv/lib/python3.10/site-packages/django/views/debug.py", line 156, in get_safe_settings
2024-10-08 13:19:15,157: settings_dict[k] = self.cleanse_setting(k, getattr(settings, k))
2024-10-08 13:19:15,157:
2024-10-08 13:19:15,157: File "/home/SirJude/Blog/.venv/lib/python3.10/site-packages/django/conf/__init__.py", line 98, in __getattr__
2024-10-08 13:19:15,157: raise ImproperlyConfigured("The SECRET_KEY setting must not be empty.")