Skip to content

Instantly share code, notes, and snippets.

Last active June 28, 2022 20:49
What would you like to do?
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 =
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