在Django上由<function wrapper at 0x7f2f82ee3aa0>启动的线程中未处理的异常

Unhandled exception occurs while passing function inside models.py in Django (installing by pip install numpy django requests)

我正在尝试使用OpenCV,Numpy和Redis在Web上操纵面部检测API . 但是我在models.py中传递函数有一个例外我只是关于Django框架和Python语言的新手 .

运行我的Django服务器时出现错误!

Traceback启动的线程中未处理的异常(最近一次调用最后一次):文件“/home/xyz/.xyz/lib/python2.7/site-packages/django/utils/autoreload.py”,第227行,在包装器fn中(* args,** kwargs)文件“/home/xyz/.xyz/lib/python2.7/site-packages/django/core/management/commands/runserver.py”,第117行,在inner_run中autoreload.raise_last_exception( )文件“/home/xyz/.xyz/lib/python2.7/site-packages/django/utils/autoreload.py”,第250行,在raise_last_exception six.reraise(* _ exception)文件“/ home / xyz / . xyz / lib / python2.7 / site-packages / django / utils / autoreload.py“,第227行,在包装器fn(* args,** kwargs)文件”/home/xyz/.xyz/lib/python2.7 /site-packages/django/init.py“,第27行,在安装程序apps.populate(settings.INSTALLED_APPS)文件”/home/xyz/.xyz/lib/python2.7/site-packages/django/apps/registry .py“,第108行,填充app_config.import_models()文件”/home/xyz/.xyz/lib/python2.7/site-packages/django/apps/config.py“,第202行,在import_models self中 . models_module = import_module(models_modul e_name)文件“/usr/lib/python2.7/importlib/init.py”,第37行,在import_module导入(名称)文件“/home/xyz/PycharmProjects/xyz_project/OpencvWeb/opencv_api/Face_detection/models.py” ,第28行,在LFace类:文件“/home/xyz/PycharmProjects/xyz_project/OpencvWeb/opencv_api/Face_detection/models.py”,第29行,在LFace def init(self,faceRect = LRect(),eyes = [] ,id = 0,mt = 0,vel = LVector(0,0)):NameError:名称'LRect'未定义

这是我在models.py中的代码
这是LFace的课程

class LFace:
    def __init__(self, faceRect = LRect(), eyes=[], id = 0, mt = 0, vel = LVector(0,0)):
        self.face = faceRect.clone()
        self.eyes = [e.clone() for e in eyes]
        self.id = id
        self.name = ''
        self.missingTicks = mt
        self.velocity = vel
    def clone(self):
        return LFace(self.face, self.eyes, self.id)
    def setAs(self, f2):
        self.face = f2.face.clone()
        self.eyes = [e.clone() for e in f2.eyes]
        self.id = f2.id
        self.missintTicks = f2.missingTicks
        self.velocity = f2.velocity.clone()
    def dist(self, f2, scalar1 = 1.0, scalar2 = 0.2):
    #distance is defined as: center differences * scalar1 + size differences * scalar2
        d1 = self.face.center().dist(f2.face.center())
        d2 = self.face.wh().dist(f2.face.wh())
        return d1 * scalar1 + d2 * scalar2
    def interpolateTo(self, f2, t):
        self.face.interpolateTo(f2.face, t)
        self.eyes = f2.clone().eyes if t > 0.5 else []
    def getPredicted(self):
        rv = self.clone()
        p = rv.face.center()
        oldP = p.clone()
        p += self.velocity
        rv.velocity = LVector(0,0)
        rv.face.setFromCenter(p)
        return rv

这是LRect的课程

class LRect:  
        def __init__(self, x=0, y=0, w=0, h=0):
            self.x = x
            self.y = y
            self.w = w
            self.h = h

        def pos(self):
            return LVector(self.x, self.y)

        def wh(self):
            return LVector(self.w, self.h)

        def hwh(self):
            return LVector(self.w, self.h) * 0.5

        def center(self):
            return (self.pos() + self.hwh())

        def toString(self):
            return '[x={0},y={1},width={2},height={3}]'.format(*self.toList())

        def __str__(self):
            return self.toString()

        def toList(self):
            return [self.x, self.y, self.w, self.h]

        def clone(self):
            return LRect(self.x, self.y, self.w, self.h)

        def setFromCenter(self, centerPoint):
            hp = self.hwh()
            self.x = centerPoint[0] - hp[0]
            self.y = centerPoint[1] - hp[1]

        def scaleWH(self, scalar):
            # scalar can be either an LVector or a number
            c = self.center()
            hwh = self.wh() * scalar
            self.w, self.h = hwh[0], hwh[1]
            self.setFromCenter(c)

        def interpolateTo(self, r2, t):
            c = self.center()
            wh = self.wh()
            c.interpolateTo(r2.center(), t)
            wh.interpolateTo(r2.wh(), t)
            self.w, self.h = wh[0], wh[1]
            self.setFromCenter(c)

请帮助!!

回答(0)