Skip to content

Instantly share code, notes, and snippets.

@aliceridgway
Last active Jun 28, 2022
Embed
What would you like to do?
edit_post
def edit_post(request: HttpRequest, slug: str) -> HttpResponse:
post = get_object_or_404(Post, slug=slug)
form = PostForm(instance=post)
if request.method == "POST":
form = PostForm(request.POST, instance=post)
if form.is_valid():
post = form.save()
return redirect("post_detail", slug=post.slug)
context = {"form": form, "post": post, "edit_mode": True}
return render(request, "post_form.html", context)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment