Django database query: How to get object by id?

前端 未结 6 1614
遇见更好的自我
遇见更好的自我 2021-01-30 19:05

Django automatically creates an id field as primary key.

Now I need to get the object by this id.

object = Class.objects.filter() 

How

6条回答
  •  你的背包
    2021-01-30 19:41

    You can also do:

    obj = ClassModel.get_by_id(object_id)
    
    

    This works, but there may I'm not sure if it's supported in Django 2.

提交回复
热议问题