【问题标题】:Django db name 'connection' is not defined未定义 Django 数据库名称“连接”
【发布时间】:2018-11-19 14:20:21
【问题描述】:

我在 django + mysql 中制作我的第一个项目,这里的问题是它通知我没有定义名称“连接”。我不知道为什么。没有人能解释我吗? 从 django.db 导入连接 导入cv2

def 检测(请求):

faceDetect = cv2.CascadeClassifier(BASE_DIR + '/haarcascade_frontalface_default.xml')

cam = cv2.VideoCapture(0)
# creating recognizer
rec = cv2.face.LBPHFaceRecognizer_create();
# loading the training data
rec.read(BASE_DIR + '/recognizer/trainingData.yml')
getId = 0
font = cv2.FONT_HERSHEY_SIMPLEX
maSv = 0
while(True):
    ret, img = cam.read()
    gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
    faces = faceDetect.detectMultiScale(gray, 1.3, 5)
    for(x,y,w,h) in faces:
        cv2.rectangle(img,(x,y),(x+w,y+h), (0,255,0), 2)

        getId,conf = rec.predict(gray[y:y+h, x:x+w]) #This will predict the id of the face

        #print conf;
        if conf<35:
            maSv = getId
            cv2.putText(img, str(maSv),(x,y+h), font, 2, (0,255,0),2)
            maSV = str(maSv)
            with connection.cursor() as cursor:
                cursor.callproc('diemdanh', [maSV, '101B1'])
        else:
            cv2.putText(img, "Unknown",(x,y+h), font, 2, (0,0,255),2)

        # Printing that number below the face
        # @Prams cam image, id, location,font style, color, stroke

    cv2.imshow("Face",img)
    if(cv2.waitKey(1) == ord('q')):
        break
    elif(maSv != 0):
        cv2.waitKey(1000)
        cam.release()
        cv2.destroyAllWindows()
        return redirect('/')

cam.release()
cv2.destroyAllWindows()
return redirect('/')

【问题讨论】:

  • 不是数据库,变量connection本身没有定义。

标签: python mysql django


【解决方案1】:

您是否导入了连接

试试:

from django.db import connection

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-05-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-07-19
    • 1970-01-01
    • 1970-01-01
    • 2022-06-15
    相关资源
    最近更新 更多