django.shortcuts import redirect, render from .forms import BookForm from .models import Book def edit_book(request, pk): try: book = Book.objects.get(id=pk) except Book.DoesNotExist: raise Http404("Book does not exist") if request.method == 'GET': form = BookForm(instance=book) return render(request, 'my-book-edit.html', {'form': form, 'object': book}) if request.method == 'POST': book = Book.objects.get(id=pk) form = BookForm(request.POST, instance=book) if form.is_valid(): form.save() return redirect('/old/my-books') And we didn’t treat all cases!