Activate the "Edit" button
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. In the main.py
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.
2. Change the make-post.html
so that 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".
3. Fix the href
for the edit button in the post.html
and pass over the post's id.
e.g.
Auto-populate the form fields for an existing post
1. When you head over to make-post.html
the form should be populated with the existing content when editing an old post. Add the code to 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 )
Redirect the user to the blog entry after submitting their edits
1. 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.