Python 3.x 从Apache运行自定义Django命令 客观的

Python 3.x 从Apache运行自定义Django命令 客观的,python-3.x,django,apache,raspberry-pi,wsgi,Python 3.x,Django,Apache,Raspberry Pi,Wsgi,我正在尝试将Django中的应用程序部署到raspberryPi上的Apache,以便能够从连接到同一wifi的另一台PC访问我的网站 安装程序 阿帕奇 现在我有以下Apache默认配置文件 /etc/apache2/sites available/000 default.conf <VirtualHost *:443> # The ServerName directive sets the request scheme, hostname and port that

我正在尝试将Django中的应用程序部署到raspberryPi上的Apache,以便能够从连接到同一wifi的另一台PC访问我的网站

安装程序 阿帕奇 现在我有以下Apache默认配置文件

/etc/apache2/sites available/000 default.conf

<VirtualHost *:443>
    # The ServerName directive sets the request scheme, hostname and port that
    # the server uses to identify itself. This is used when creating
    # redirection URLs. In the context of virtual hosts, the ServerName
    # specifies what hostname must appear in the request's Host: header to
    # match this virtual host. For the default virtual host (this file) this
    # value is not decisive as it is used as a last resort host regardless.
    # However, you must set it for any further virtual host explicitly.
    ServerName www.example.com

    ServerAdmin webmaster@localhost
    #DocumentRoot /var/www/html

    # Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
    # error, crit, alert, emerg.
    # It is also possible to configure the loglevel for particular
    # modules, e.g.
    LogLevel info debug

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

    # For most configuration files from conf-available/, which are
    # enabled or disabled at a global level, it is possible to
    # include a line for only one particular virtual host. For example the
    # following line enables the CGI configuration for this host only
    # after it has been globally disabled with "a2disconf".
    #Include conf-available/serve-cgi-bin.conf

    Alias /static /home/pi/ledypi/ledyweb/static
    <Directory /home/pi/ledypi/ledyweb/static>
         AllowOverride all 
        Require all granted 
        Options FollowSymlinks
    </Directory>

    <Directory /home/pi/ledypi/ledyweb/ledyweb>
        <Files wsgi.py>
            Require all granted
        </Files>
    </Directory>
    WSGIDaemonProcess ledyweb python-path=/home/pi/ledypi/src:/home/pi/ledypi/audio-reactive-led-strip/src:/home/pi/ledypi/ledyweb python-home=/home/pi/ledypi_venv/
    WSGIProcessGroup ledyweb
    WSGIScriptAlias / /home/pi/ledypi/ledyweb/wsgi.py

</VirtualHost>

# vim: syntax=apache ts=4 sw=4 sts=4 sr noet
wsgi文件具有:

/home/pi/ledypi/ledyweb/ledyweb/wsgi.py

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

import os
from django.conf import settings
from django.core.wsgi import get_wsgi_application
from django.contrib.staticfiles.handlers import StaticFilesHandler

os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'ledyweb.settings')
if settings.DEBUG:
    application = StaticFilesHandler(get_wsgi_application())
else:
    application = get_wsgi_application()
import logging
import os

from django.core.management.commands import runserver

from Home.views.fire_view import FV

django_logger = logging.getLogger("django_logger")


class Command(runserver.Command):
    help = 'Start Firebase connection '

    def add_arguments(self, parser):
        super(Command, self).add_arguments(parser)
        parser.add_argument('credential_path', type=str,
                            help='The path to the private key json file for Firebase')
        # Optional argument
        parser.add_argument('--databaseURL', type=str, nargs='?', default="https://ledypie.firebaseio.com/",
                            help='The Firebase database url')

        parser.add_argument('--debug', nargs='?', const=True,
                            help='If to start in debug mode')

    def handle(self, *args, **options):
        if os.environ.get('RUN_MAIN') == 'true':
            if options['debug']:
                django_logger.setLevel(logging.DEBUG)

            FV.init_firebase(options)
            django_logger.info("Initialized firebase")

        super(Command, self).handle(*args, **options)

当我使用
sudoapachectl restart
运行apache服务器时,我没有收到任何错误,但该页面是apache的默认空页面

自定义命令启动 我注意到在线教程的唯一区别是,我使用了一个自定义命令,
start.py
,来启动我的应用程序

/home/pi/ledypi/ledyweb/home/management/commands/start.py

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

import os
from django.conf import settings
from django.core.wsgi import get_wsgi_application
from django.contrib.staticfiles.handlers import StaticFilesHandler

os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'ledyweb.settings')
if settings.DEBUG:
    application = StaticFilesHandler(get_wsgi_application())
else:
    application = get_wsgi_application()
import logging
import os

from django.core.management.commands import runserver

from Home.views.fire_view import FV

django_logger = logging.getLogger("django_logger")


class Command(runserver.Command):
    help = 'Start Firebase connection '

    def add_arguments(self, parser):
        super(Command, self).add_arguments(parser)
        parser.add_argument('credential_path', type=str,
                            help='The path to the private key json file for Firebase')
        # Optional argument
        parser.add_argument('--databaseURL', type=str, nargs='?', default="https://ledypie.firebaseio.com/",
                            help='The Firebase database url')

        parser.add_argument('--debug', nargs='?', const=True,
                            help='If to start in debug mode')

    def handle(self, *args, **options):
        if os.environ.get('RUN_MAIN') == 'true':
            if options['debug']:
                django_logger.setLevel(logging.DEBUG)

            FV.init_firebase(options)
            django_logger.info("Initialized firebase")

        super(Command, self).handle(*args, **options)

该命令添加一个强制参数(凭证路径)和两个可选参数

问题: 现在我的问题是如何修改wgsi文件,以便像往常一样运行start命令? 我应该从Apache还是Django来做

附加信息
  • 我在web服务器方面没有经验,在Django方面也只有一点经验
  • Python版本:Python 3.7.3
  • 拉斯比版本:10(巴斯特)