首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何使Open在部署的web应用程序上工作

如何使Open在部署的web应用程序上工作
EN

Stack Overflow用户
提问于 2019-11-04 11:53:14
回答 2查看 795关注 0票数 1

我有一个应用程序,我可以在本地运行,让它打开我的网络相机,然后检测qr代码。当我在本地运行应用程序时,它运行得很好,但是我在我的web服务器上使用了这个应用程序,它得到了一个服务器错误(500)。

这个应用程序是在Django上制作的,然后在部署时我使用了数字海洋(Ubuntu),我还使用了nginx和gunicorn。

html

代码语言:javascript
复制
<li style= "margin: auto; width:auto"><a style="color:white" href="{% url 'attendees:qrscanner' %}" target="_blank"><button style="margin:15px; width:200px" class="btn btn-outline-primary">Check QR Scanner</button></a></li>

views.py

代码语言:javascript
复制
from django.shortcuts import get_object_or_404, render, redirect
from django.utils import timezone
from django.db.models import Sum
from .models import Attendee, ActivityLog

import re, qrcode, cv2, csv, io, os
import numpy as np
import pyzbar.pyzbar as pyzbar

def qrscanner(request):
    cap = cv2.VideoCapture(0)
    font = cv2.FONT_HERSHEY_PLAIN

    frame_width = int(cap.get(3))
    frame_height = int(cap.get(4))

    aid = None

    while aid is None:
        _, frame = cap.read()

        decodedObjects = pyzbar.decode(frame)

        for obj in decodedObjects:
            aid = re.findall('/attendees/confirmation/([0-9]+)', str(obj.data))
            try:
                attendee = Attendee.objects.get(pk=str(aid[0]))
                attendee.present = True
                attendee.timestamp = timezone.now()
                attendee.activity.update_or_create(time_log=attendee.timestamp)
                attendee.save()
                context = {
                    'scan': 'QR Successfully Scanned',
                    'attendee': attendee,
                }
            except:
                context = {
                    'noscan': 'QR Scan Unsuccessful'
                }


        cv2.imshow("QR Reader", frame)

        if aid is not None:
            cv2.destroyAllWindows()
            break

        key = cv2.waitKey(1) & 0xFF
        if key == 27:
            context = {
                'noscan': 'No QR Scanned',
            }
            cv2.destroyAllWindows()
            break

    return render(request, 'attendees/qrscanner.html', context)

预期的结果:当我的应用程序在本地运行时,我会去我的网站,在我的网站上包含这个应用程序,我点击qr扫描仪按钮,然后点击“cap=cv2”,用我的电脑摄像头打开一个框架来检测qr。

实际结果: -locally everything很好,我单击qr扫描器按钮和“cap= cv2.VideoCapture(0)”打开了一个使用我的计算机摄像机检测qr的帧。但是在我的网站上,一旦我访问了应用程序的那个部分,我就会得到服务器错误(500)。

注意: -I必须通过pip安装一些额外的文件,才能让应用程序显示一些html,我在网站上还有其他的应用程序。在本地安装的图书馆(pip冻结):

代码语言:javascript
复制
colorama==0.4.1
dj-database-url==0.5.0
Django==2.2.3
django-qr-code==1.0.0
django-widget-tweaks==1.4.5
docutils==0.15.2
mysqlclient==1.4.2
numpy==1.17.0
opencv-python==4.1.0.25
pathlib==1.0.1
Pillow==6.0.0
python-decouple==3.1
pytz==2019.1
pyzbar==0.1.8
qrcode==6.1
six==1.12.0
sqlparse==0.3.0

安装在网站上的图书馆(pip冻结):

代码语言:javascript
复制
beautifulsoup4==4.8.0
certifi==2019.9.11
chardet==3.0.4
cycler==0.10.0
demjson==2.2.4
Django==2.2.6
django-authentication==3.2
django-qr==2.0
django-realestate==4.0
django-widget-tweaks==1.4.5
gunicorn==19.9.0
idna==2.8
jtutils==0.0.6
kiwisolver==1.1.0
leven==1.0.4
matplotlib==3.1.1
nose==1.3.7
numpy==1.17.2
opencv-python==4.1.1.26
opencv-python-headless==4.1.1.26
pandas==0.25.1
Pillow==6.2.0
pkg-resources==0.0.0
psycopg2==2.8.3
psycopg2-binary==2.8.3
pyparsing==2.4.2
python-csv==0.0.11
python-dateutil==2.8.0
pytz==2019.2
pyzbar==0.1.8
qrcode==6.1
requests==2.22.0
six==1.12.0
soupsieve==1.9.4
sqlparse==0.3.0
urllib3==1.25.6
xlrd==1.2.0
xmltodict==0.12.0
EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2020-02-15 00:55:05

这里是这方面的实际javascript指南。

Git源

票数 0
EN

Stack Overflow用户

发布于 2019-11-04 11:55:52

问题是cap=cv2. actually (0)实际上是试图在部署应用程序的服务器上打开网络摄像头,而不是在计算机上打开网络摄像头。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/58692917

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档