By now, all of the logic we have gone over so far will take you a long way so let's just finish up quickly with updating and deleting a posts. We'll assume you are comfortable with what we have learned so far so we will run through this faster since this is just more of what were in the previous parts.
Update Controller Method
Let's just make an update method on the PostController:
app/http/controllers/PostController.py
defupdate(self): post = Post.find(request().param('id'))returnview('update', {'post': post})defstore(self): post = Post.find(request().param('id')) post.title =request().input('title') post.body =request().input('body') post.save()return'post updated'
Since we are more comfortable with controllers we can go ahead and make two at once. We made one that shows a view that shows a form to update a post and then one that actually updates the post with the database.
Notice we used a GET route here, It would be much better to use a POST method but for simplicity sake will assume you can create one by now. We will just add a link to our update method which will delete the post.
Update the Template
We can throw a delete link right inside our update template: