Skip to content

Instantly share code, notes, and snippets.

@aliceridgway
Created June 25, 2022 21:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aliceridgway/157f7ba50a17b42efaf941089817052a to your computer and use it in GitHub Desktop.
Save aliceridgway/157f7ba50a17b42efaf941089817052a to your computer and use it in GitHub Desktop.
add_post
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