-
-
Save aliceridgway/157f7ba50a17b42efaf941089817052a to your computer and use it in GitHub Desktop.
add_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 add_post(request: HttpRequest) -> HttpResponse: | |
if request.method == "POST": | |
form = PostForm(request.POST) | |
if form.is_valid(): | |
# form.save() creates a post from the form | |
post = form.save() | |
return redirect("post_detail", slug=post.slug) | |
else: | |
form = PostForm() | |
context = {"form": form, "edit_mode": False} | |
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