通过 apache2 运行 django 应用程序时无法找到 django 错误

通过 apache2 运行 django 应用程序时无法找到 django 错误

我正在尝试在 apache2 服务器和 raspberry pi 上运行一个 django 应用程序,用于我的一个项目。appache 服务器正在运行,但我无法打开网页,因为我只收到“内部服务器错误”//日志文件

[Fri Apr 07 19:28:44.334749 2023] [wsgi:error] [pid 24119:tid 1965745152] [remote 192.168.50.249:54720] mod_wsgi (pid=24119): Failed to exec Python script file '/home/pi/greenhouse/greenhouse/wsgi.py'.
[Fri Apr 07 19:28:44.335018 2023] [wsgi:error] [pid 24119:tid 1965745152] [remote 192.168.50.249:54720] mod_wsgi (pid=24119): Exception occurred processing WSGI script '/home/pi/greenhouse/greenhouse/wsgi.py'.
[Fri Apr 07 19:28:44.335914 2023] [wsgi:error] [pid 24119:tid 1965745152] [remote 192.168.50.249:54720] Traceback (most recent call last):
[Fri Apr 07 19:28:44.336045 2023] [wsgi:error] [pid 24119:tid 1965745152] [remote 192.168.50.249:54720]   File "/home/pi/greenhouse/greenhouse/wsgi.py", line 12, in <module>
[Fri Apr 07 19:28:44.336068 2023] [wsgi:error] [pid 24119:tid 1965745152] [remote 192.168.50.249:54720]     from django.core.wsgi import get_wsgi_application
[Fri Apr 07 19:28:44.336139 2023] [wsgi:error] [pid 24119:tid 1965745152] [remote 192.168.50.249:54720] ModuleNotFoundError: No module named 'django'

我的 000-default.conf 文件

<VirtualHost *:80>

    #ServerName www.example.com

    ServerAdmin webmaster@localhost
    DocumentRoot /var/www/html

    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined

    Alias /static /home/pi/greenhouse/static
    <Directory /home/pi/greenhouse/static>
        Require all granted
    </Directory>

    <Directory /home/pi/greenhouse/greenhouse>
    <Files wsgi.py>
        Require all granted
    </Files>
    </Directory>
    
    WSGIDaemonProcess greenhouse python-path=/home/pi/greenhouse python-home=/home/pi/greenhouse/greenhouseenv
    WSGIProcessGroup greenhouse
    WSGIScriptAlias / /home/pi/greenhouse/greenhouse/wsgi.py
</VirtualHost>

# vim: syntax=apache ts=4 sw=4 sts=4 sr noet

我的 wsgi.py 文件

"""
WSGI config for greenhouse 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/4.1/howto/deployment/wsgi/
"""

import os

from django.core.wsgi import get_wsgi_application

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

application = get_wsgi_application()

我已确保 django 安装在虚拟环境中,并尝试了其他一些方法,但都无济于事。

相关内容