【发布时间】:2022-01-11 14:41:54
【问题描述】:
我试图在循环结束后返回相同的响应,但我找不到实现它的方法。
在这里,我尝试过的错误是在分配之前引用了局部变量“TaskId”
views.py:
def GetCurrentRunningActivity(UserID):
cursor = connection.cursor()
cursor.execute('EXEC [dbo].[sp_GetCurrentRunningActivity] @UserId=%s',(UserID,))
result_set = cursor.fetchall()
cursor_set = cursor.fetchall()
for row in result_set:
TaskId=row[0]
Number=row[1]
Opened=row[2]
Contacttype=row[3]
Category1=row[4]
State=row[5]
Assignmentgroup=row[6]
CountryLocation=row[7]
Openedfor=row[8]
Employeenumber=row[9]
Shortdescription=row[10]
Internaldescription=row[11]
Additionalcomments=row[12]
TaskName = row[1]
print("Number", Number)
return Response({ "TaskId": TaskId, "Number":Number,"Opened":Opened, "Contacttype":Contacttype,
"Category1":Category1, "State":State, "Assignmentgroup":Assignmentgroup, "CountryLocation":CountryLocation,
"Openedfor":Openedfor, "Employeenumber":Employeenumber , "Shortdescription":Shortdescription,
"Internaldescription":Internaldescription, "Additionalcomments":Additionalcomments,"TaskName":TaskName},status=status.HTTP_200_OK)
return Response({ "TaskId": TaskId, "Number":Number,"Opened":Opened, "Contacttype":Contacttype,
"Category1":Category1, "State":State, "Assignmentgroup":Assignmentgroup, "CountryLocation":CountryLocation,
"Openedfor":Openedfor, "Employeenumber":Employeenumber , "Shortdescription":Shortdescription,
"Internaldescription":Internaldescription, "Additionalcomments":Additionalcomments,"TaskName":TaskName},status=status.HTTP_200_OK)
【问题讨论】:
标签: django django-rest-framework django-views