-
-
Save aliceridgway/a4547d497c5accb13553e6dc05aaa69f to your computer and use it in GitHub Desktop.
edit_post
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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