如何获取对象的某些属性?

2024-09-26 22:12:22 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在使用Django框架进行编码,我被困在这个问题上:

usercomment = 'Test'
usercomments = json.dumps(usercomment)
data = {
    'date': '2019-02-06',
    'usercomments': usercomments,
    'totalminutes': '120',
    'searched': 'functionTest'
}

在这一行,我在数据库中创建条目。你知道吗

response = self.client.post("/urlRegistration/", data=data, follow=True) 

但是,当我想获得在数据库中创建的对象的唯一id时,我不能,因为连接已关闭

myObject = Myobject.objects.filter(usercomment=usercomment)
uniqueid = myObject[0].uniqueid

你能帮帮我吗?你知道吗

非常感谢!你知道吗

编辑:Python告诉我:

cursor = self.connection.cursor()
psycopg2.InterfaceError: connection already closed

对于我得到的变量响应:<HttpResponse status_code=200, "application/json">


Tags: djangotestself框架数据库json编码data

热门问题