Writing a Blog App using Django

Whaaat, a Blog inside a Blog?


My last Python web project was Finance. A stocks trading simulator for CS50, Harvard’s Introductory Course to Computer Science. This project had me writing quite a fun amount of Python code using the Flask framework for web apps. It took me a while to finish and it was a rewarding experience. The staff of CS50 decided to use Flask for the course because it is simple and, in a way, straightforward. Which is actually the style of the course.

Django has been around longer than Flask and has a more robust documentation and a stronger community. It also is more adopted in the industry and widely known to have a larger number of tools and features than Flas. This is not to say that Flask is bad or “worse” in comparison, not at all. It’s just that Django is more “complete” and richer, and thus, more widely adopted by engineers seeking to grab more practice. For this reason, I decided to learn me some Django and after reading the amazing Python Crash Course by Eric Matthes, I started writing a little project: a Blog.

A quick tour

The following image exemplifies what the user sees when visiting the website.


The home page shows the latest five blog posts. It gives the reader a short preview of the body of the post, as well as showing the author’s name, the date the post was added and the relevant tags.

Let’s click on a Post to get a full view:


Because I love The Lord of The Rings.

As we can see, the page gives us a nice, clean and easy to read view with the Solarized theme. This page, again, shows the user the date the post was added, and all the relevant tags.

Let’s click on a tag and see what happens:


As we can see, this page shows us all the other posts that also share the tag we clicked, in this case, “Reading”. We can see that every posts is shown as only a short preview of its body, otherwise the page would be too cluttered, even with small, example, nonsense posts. I really need to finish that Napoleon Biography before the movie drops.

How are new blog posts created? First we have to notice a little thing. See how the web app identifies if the current user is logged in or not in the heading:


Thus, this tells us that an unregistered user can not add new Blog Posts. This web app uses Django’s authentication system, which regarding logins, pretty much does all the job for us. Here’s the login page:


Once we have logged in, we can create new blog posts in the new_post page, this is how it looks:


And that is pretty much it!

You can check the code in the repo: https://github.com/UberChili/Blog-app-using-Django

Thank you for reading!