0
@app.post(path='/create')
def create_record(request: Request,sid: str = Form(...), name: str = Form(...),last_name: str = Form (...), email: str = Form(...),
                   add: str = Form(...), gpa: str = Form(...)):
    import mysql.connector
    cnx = mysql.connector.connect(user='NOPE', host='NOPE', database='NOPE', password='NOPE')
    cursor = cnx.cursor()
    query = "INSERT INTO `StudentInfo`.`Student` (`StudentId`, `FirstName`, `LastName`, `Email`, `Address`, `GPA`) VALUES ('%s', '%s','%s','%s','%s','%s');"%(sid ,name ,last_name ,email ,add ,gpa)
    print(query)
    if query is None:
        raise HTTPException(status_code=500, detail="Student ID or email already exists, please check what you've "
                                                    "entered and retry or contact Administrator.")
    else:
        cursor.execute(query)
        cnx.commit()
        cursor.close()
        return templates.TemplateResponse("extend_5.html", {"request": request})

所以基本上,代码总是显示“内部服务器错误”页面,而不是我在那里写的。我没有正确捕捉到异常吗?

当有人输入相同的学生 ID 或电子邮件时,它应该显示“学生 ID 或电子邮件已存在,请检查....”

我对 Web Dev 和 FastAPI 很陌生,我做错了什么?

4

0 回答 0