Django not connected to the Apache server

This error came up when I tried to match Django with Apache 2.4. But when I access the server, I get 500 errors I haven't solved this error yet

error code

[Mon Nov 13 20:44:10.540478 2023] [wsgi:error] [pid 16020:tid 1112] [client ::1:51548] mod_wsgi (pid=16020): Failed to exec Python script file 'C:/Apache24/htdocs/django_file/ranking/ranking/wsgi.py'.
[Mon Nov 13 20:44:10.540478 2023] [wsgi:error] [pid 16020:tid 1112] [client ::1:51548] mod_wsgi (pid=16020): Exception occurred processing WSGI script 'C:/Apache24/htdocs/django_file/ranking/ranking/wsgi.py'.
[Mon Nov 13 20:44:10.540478 2023] [wsgi:error] [pid 16020:tid 1112] [client ::1:51548] Traceback (most recent call last):\r
[Mon Nov 13 20:44:10.540478 2023] [wsgi:error] [pid 16020:tid 1112] [client ::1:51548]   File "C:/Apache24/htdocs/django_file/ranking/ranking/wsgi.py", line 19, in <module>\r
[Mon Nov 13 20:44:10.540478 2023] [wsgi:error] [pid 16020:tid 1112] [client ::1:51548]     application = get_wsgi_application()\r
[Mon Nov 13 20:44:10.540478 2023] [wsgi:error] [pid 16020:tid 1112] [client ::1:51548]                   ^^^^^^^^^^^^^^^^^^^^^^\r
[Mon Nov 13 20:44:10.540478 2023] [wsgi:error] [pid 16020:tid 1112] [client ::1:51548]   File "C:\\Users\\dkdle\\AppData\\Local\\Programs\\Python\\Python311\\Lib\\site-packages\\django\\core\\wsgi.py", line 12, in get_wsgi_application\r
[Mon Nov 13 20:44:10.540478 2023] [wsgi:error] [pid 16020:tid 1112] [client ::1:51548]     django.setup(set_prefix=False)\r
[Mon Nov 13 20:44:10.540478 2023] [wsgi:error] [pid 16020:tid 1112] [client ::1:51548]   File "C:\\Users\\dkdle\\AppData\\Local\\Programs\\Python\\Python311\\Lib\\site-packages\\django\\__init__.py", line 19, in setup\r
[Mon Nov 13 20:44:10.540478 2023] [wsgi:error] [pid 16020:tid 1112] [client ::1:51548]     configure_logging(settings.LOGGING_CONFIG, settings.LOGGING)\r
[Mon Nov 13 20:44:10.540478 2023] [wsgi:error] [pid 16020:tid 1112] [client ::1:51548]                       ^^^^^^^^^^^^^^^^^^^^^^^\r
[Mon Nov 13 20:44:10.540478 2023] [wsgi:error] [pid 16020:tid 1112] [client ::1:51548]   File "C:\\Users\\dkdle\\AppData\\Local\\Programs\\Python\\Python311\\Lib\\site-packages\\django\\conf\\__init__.py", line 102, in __getattr__\r
[Mon Nov 13 20:44:10.540478 2023] [wsgi:error] [pid 16020:tid 1112] [client ::1:51548]     self._setup(name)\r
[Mon Nov 13 20:44:10.540478 2023] [wsgi:error] [pid 16020:tid 1112] [client ::1:51548]   File "C:\\Users\\dkdle\\AppData\\Local\\Programs\\Python\\Python311\\Lib\\site-packages\\django\\conf\\__init__.py", line 89, in _setup\r
[Mon Nov 13 20:44:10.540478 2023] [wsgi:error] [pid 16020:tid 1112] [client ::1:51548]     self._wrapped = Settings(settings_module)\r
[Mon Nov 13 20:44:10.540478 2023] [wsgi:error] [pid 16020:tid 1112] [client ::1:51548]                     ^^^^^^^^^^^^^^^^^^^^^^^^^\r
[Mon Nov 13 20:44:10.540478 2023] [wsgi:error] [pid 16020:tid 1112] [client ::1:51548]   File "C:\\Users\\dkdle\\AppData\\Local\\Programs\\Python\\Python311\\Lib\\site-packages\\django\\conf\\__init__.py", line 217, in __init__\r
[Mon Nov 13 20:44:10.540478 2023] [wsgi:error] [pid 16020:tid 1112] [client ::1:51548]     mod = importlib.import_module(self.SETTINGS_MODULE)\r
[Mon Nov 13 20:44:10.540478 2023] [wsgi:error] [pid 16020:tid 1112] [client ::1:51548]           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\r
[Mon Nov 13 20:44:10.540478 2023] [wsgi:error] [pid 16020:tid 1112] [client ::1:51548]   File "C:\\Users\\dkdle\\AppData\\Local\\Programs\\Python\\Python311\\Lib\\importlib\\__init__.py", line 126, in import_module\r
[Mon Nov 13 20:44:10.540478 2023] [wsgi:error] [pid 16020:tid 1112] [client ::1:51548]     return _bootstrap._gcd_import(name[level:], package, level)\r
[Mon Nov 13 20:44:10.540478 2023] [wsgi:error] [pid 16020:tid 1112] [client ::1:51548]            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\r
[Mon Nov 13 20:44:10.540478 2023] [wsgi:error] [pid 16020:tid 1112] [client ::1:51548]   File "<frozen importlib._bootstrap>", line 1204, in _gcd_import\r
[Mon Nov 13 20:44:10.540478 2023] [wsgi:error] [pid 16020:tid 1112] [client ::1:51548]   File "<frozen importlib._bootstrap>", line 1176, in _find_and_load\r
[Mon Nov 13 20:44:10.540478 2023] [wsgi:error] [pid 16020:tid 1112] [client ::1:51548]   File "<frozen importlib._bootstrap>", line 1135, in _find_and_load_unlocked\r
[Mon Nov 13 20:44:10.540478 2023] [wsgi:error] [pid 16020:tid 1112] [client ::1:51548] ModuleNotFoundError: No module named 'ranking.settings'; 'ranking' is not a package\r

python 3.11.5 windows 11

I have this virtual host

<VirtualHost *:80>
    ServerName my server domain

    WSGIScriptAlias / "C:/Apache24/htdocs/django_file/ranking/ranking/wsgi.py"
    WSGIPassAuthorization On

    <Directory "C:/Apache24/htdocs/django_file/ranking/ranking">
        Options +ExecCGI
        AddHandler wsgi-script .py
        Require all granted
    </Directory>
</VirtualHost>

django wsgi.py code

import os

import sys
sys.path.append('/path/to/ranking/module')

from django.core.wsgi import get_wsgi_application

os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'ranking.settings')

application = get_wsgi_application()

Back to Top