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 .
You need to change here:
from django.shortcuts import render
def del_note(request, note_id):
x = Note.objects.get(id = note_id) # <-- Here
print (x) // tried for degugging
x.delete()
return redirect("/")
def edit_note(request, note_id):
x = Note.objects.get( id = note_id) # <-- Here
form = NoteForm(request.POST or None, instance=x)
if request.method == "POST":
if form.is_valid():
form.save()
return redirect("/")
return render(request, 'edit_template.html', context={'form':form,'sticky':x})
# edit_template.html
The error was occurring because you passed id, but you should pass note_id instead.