0

我正在使用 Apache2 和 WSGI 托管一个简单的 Django 网站。该网站运行良好,但是当我尝试实例化 PiCamera() 对象时,我收到此错误。我要做的就是每次刷新网站时启动照片捕获并更新网站上的图像。我觉得应该没那么难。

我已经搜索了所有内容,但找不到解决方案。我试图将 WSGIApplicationGroup %{GLOBAL} 添加到我的 sites-available/000-default.conf 以及我的 apache2.conf 中。我还尝试增加头部缓冲区大小,但两种解决方案都不起作用。任何帮助,将不胜感激。

视图.py

from django.shortcuts import render
from django.http import HttpResponse
from .models import RelayList
from .forms import RelayControl
from .gpio import Update_Relays
from django.contrib.auth.decorators import login_required
from picamera import PiCamera
from time import sleep


def Snapshot():
    camera = PiCamera() #<---THIS IS WHAT CAUSES THE TRUNCATED ERROR
#   camera.start_preview()
#   sleep(5)
#   camera.capture('/home/calabi/relay_site/power_relay/media/snapshot.jpg')
#   camera.stop_preview()


# Create your views here.
@login_required
def index(response):
    curList = RelayList.objects.get(id=1) #retrieves the database object and places it into a variable
    Snapshot() #takes a photo and saves it to images directory
#   camera = PiCamera()
#   camera.start_preview()
#   sleep(5)
#   camera.capture('/home/calabi/relay_site/power_relay/media/snapshot.jpg')
#   camera.stop_preview()


    if response.method == "POST":
        form = RelayControl(response.POST, instance=curList)

        if form.is_valid():
            form.save()
            Update_Relays(curList.relay1, curList.relay2, curList.relay3)
    else:
        form = RelayControl(instance=curList) # creates an instance of the for defined in class RelayControl in forms.py

    #return HttpResponse('<h1>Hello World, from index in views.py</h1>')
    #"pageHeader" is the variable it looks for in the html file and places whatever is after the ":" in its spot
    return render(response, "power_relay/home.html", {"pageHeader":"Power Relay Controls", "controlForm":form, "curList":curList})



#@login_required
#def modify_model(response):



@login_required
def settings(response):
    return render(response, "power_relay/settings.html", {"pageHeader":"Power Relay Settings"})

000-Default.conf

<VirtualHost *:80>
    #for django
    LoadModule wsgi_module /usr/lib/apache2/modules/mod_wsgi.so

    Alias /static/admin/ /usr/local/lib/python3.9/dist-packages/django/contrib/admin/static/admin/
    <Directory /usr/local/lib/python3.9/dist-packages/django/contrib/admin/static/admin/>
                Require all granted
        </Directory>

    Alias /static_relay_site/ /home/calabi/relay_site/static/
    <Directory /home/calabi/relay_site/static>
        Require all granted
    </Directory>

    <Directory /home/calabi/relay_site>
        Require all granted
    </Directory>

    <Directory /home/calabi/relay_site/relay_site>
        <Files wsgi.py>
            Require all granted
        </Files>
    </Directory>

    WSGIDaemonProcess testing python-path=/home/calabi/relay_site
    WSGIApplicationGroup %{GLOBAL}
    WSGIProcessGroup testing
    WSGIScriptAlias / /home/calabi/relay_site/relay_site/wsgi.py process-group=testing


    # 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
    #DocumentRoot /home/calabi/relay_site

    # 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 ssl:warn

    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
</VirtualHost>

如果还有其他文件我应该发布,请告诉我。

4

0 回答 0