When you click on each of the blog posts on the home page you are taken to the post.html page for the blog post. At the end of the post, you can see an Edit Post button. When you click on this button, it should take you the make-post.html page.

1. Create a new route /edit-post/<post_id>

When the user clicks on the "Edit Post" button at the bottom of any blog post (post.html page) it should make a GET request to this route, where the post_id is the id of the post they were reading.

If the user came from "Create New Post" the <h1> should read "New Post", but if the user came to edit a particular blog post, it should read "Edit Post".

e.g.


SOLUTION


2. When you head over to make-post.html it should auto-populate the fields in the WTForm with the blog post's data. This way the user doesn't have to type out their blog post again.

You can do this by passing the post Object's properties when you create the form:

edit_form = CreatePostForm(
title=post.title,
subtitle=post.subtitle,
img_url=post.img_url,
author=post.author,
body=post.body
)

CODE


3. When the user is done editing in the WTForm, they click "Submit Post", the post should now be updated in the database. And the user redirected to the post.html page for that blog post.

NOTE: HTML forms (WTForms included) do not accept PUT, PATCH or DELETE methods. So while this would normally be a PUT request (replacing existing data), because the request is coming from a HTML form, you should accept the edited post as a POST request.

Also, the date field should not be changed, it should represent the original date the post was made. Not the date of the edit.

e.g.


SOLUTION