- model.py中,添加id = models.AutoField(primary_key=True)
'''
class Car(models.Model):
id = models.AutoField(primary_key=True)
name = models.CharField(max_length=100)
top_speed = models.IntegerField()
'''
- view.py中,调用相应参数(示例代码中为car.id)
'''
car = Car(name=car_name, top_speed=top_speed)
try:
car.save()
response = json.dumps([{ 'Success': 'Car added successfully!', 'id': car.id}])
'''
网友评论