0

I have a class

class Employee(BaseModel):
    Emp_ID: int
    Emp_Name: str
    Emp_Qualification: str

and below is code for POST request, i am getting error in last return where i was trying to get employee["Emp_id"] value.

@app.api_route("/post-details/{postid}", methods=["POST"])        
def post(postid: int , employee : Employee):
        newlist = []
        cursor=conn.cursor()
        getemploy2= "select id from employee3"
        cursor.execute(getemploy2)
        result = cursor.fetchall()
        for list in result:
                newlist.extend(list)
        if postid in newlist:
                return "yes it exist"
        return employee(["Emp_ID"])

1 Answers1

0

You can access an object's attribute with the . operator:

return employee.Emp_ID
Mureinik
  • 297,002
  • 52
  • 306
  • 350