# 11 - Blog Post Blogging

## The Blog Post Views

Now that we have all of the actions needed for the users, we still need to present, create, and manipulate the blog post model. Just like how we created the `user_view` file that contained all the user actions, we're going to use `blog_post_views.py` file to handle the blog post traffic. Then, we will add the blueprint to the `app` module, so we have access to those routes

## Create Blog Post

Start off by adding the following code to `views/blog_post_view.py` . This will start off by creating the blueprint and importing all of the dependencies needed for the views

![](https://2289778881-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LbPPMDdogM4POiHwAId%2F-LbPPg9qhO4XswC1MXCg%2F-LbPPhAVkev8EFlBiKTQ%2Fblog_post_create.png?generation=1554147631224116\&alt=media)

## Delete Post

We don't want a random user to be able to delete someone else's post. So we'll need to add that functionality. Luckily, Flask comes with the `g` object we've discussed earlier. `g` holds everything Flask needs and anything else we need to persist, into a dictionary. Add the following function to `views/blog_post_view.py`

![](https://2289778881-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LbPPMDdogM4POiHwAId%2F-LbPPg9qhO4XswC1MXCg%2F-LbPPhAX60Jqezx7z6ON%2Fblog_post_delete.jpg?generation=1554147631363031\&alt=media)

## Get All

This method is really short. All it does is grab all of the posts and returns them. There isn't a lot of room for error, so we don't need to handle anything that can go wrong. Either something gets returned, or nothing does

![](https://2289778881-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LbPPMDdogM4POiHwAId%2F-LbPPg9qhO4XswC1MXCg%2F-LbPPhAZz3HYg6TTypuR%2Fblog_post_get_all.png?generation=1554147632520146\&alt=media)

## Get one Blog Post

Instead of grabbing all of the posts, what if we just want to grab one? well, if we remember, we added a method already in the `BlogPost` model to do this. We just need to call, save the object, and return it

![](https://2289778881-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LbPPMDdogM4POiHwAId%2F-LbPPg9qhO4XswC1MXCg%2F-LbPPhAa93cjgmEfuyeW%2Fblog_post_get_one.png?generation=1554147631997824\&alt=media)

## Update Blog Post

![](https://2289778881-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LbPPMDdogM4POiHwAId%2F-LbPPg9qhO4XswC1MXCg%2F-LbPPhAcDXDNgWVyXOmd%2Fblog_post_update.png?generation=1554147632004222\&alt=media)

## Custom Response

We've seen this before with the user object but we never implemented it, nor imported it here. Let's do that

![](https://2289778881-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LbPPMDdogM4POiHwAId%2F-LbPPg9qhO4XswC1MXCg%2F-LbPPhAegja60tuJp4oN%2Fcustom_response.png?generation=1554147632480564\&alt=media)

## Registering the Blue Print

Make the `create_app` function in `src/app.py` file look like the following

![](https://2289778881-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LbPPMDdogM4POiHwAId%2F-LbPPg9qhO4XswC1MXCg%2F-LbPPhAgrmbOu8uHpIua%2Fapp.png?generation=1554147631924797\&alt=media)

## Final Steps

Run the API using the steps we took in module 10, and test the endpoints with postman just like we did before
