Field 'id' expected a number but got

后端 未结 3 586
鱼传尺愫
鱼传尺愫 2021-01-25 17:04

i want to delete and edit notes in my django app, but i am struck on this error for long Error : \"TypeError at /delete/1/ Field \'id\' expected a number but got .

3条回答
  •  后悔当初
    2021-01-25 17:56

    You have to use note_id instead of id as below...

    def del_note(request, note_id):
        x = Note.objects.get(id = note_id)
        # Your logic 
    
    
    def edit_note(request, note_id):
        x = Note.objects.get(id = note_id)
        # Your logic
    

    If you want to edit then you can do it like...

    def edit_note(request, note_id):
        x = Note.objects.get(id = note_id)
        x.field_name_1 = new_val_1
        x.field_name_2 = new_val_2
        # and so on for other fields...
        x.save()
    
    
        # Your logic
    

提交回复
热议问题