Flask is a wonderful framework for quickly making non-static websites which require a non-trivial backend. In the past, I used it to create websites such as this one, which, given a YouTube url, creates a document with the video’s text interlaced with missing words that the viewer needs to fill in himself. The website was inspired by my need to use fill-in-the-blank worksheets to practice my Italian language comprehension skills.
Flask was perfect for this task because the website is simple, but requires processing on the backend: given a url, it must download the text from the video, remove random words, and create a PDF of the exercise sheet along with a solution manual.
When I decided to write this blog, I initially tried going with Flask since I already knew the framework. However, these are the top 5 reasons why I ended up going with Jekyll instead:
To paginate posts with Flask, I have to set up the pagination items, the next page link, and the previous page link in the backend and pass them as parameters to the HTML document1. With Jekyll, I can do this entirely in the HTML document2.
Code syntax highlighting in Flask is a breeze, although to make it work I admittedly needed to refer to a stackoverflow answer3. In constrast, there is an entire section in the 2015 book “Learning Flask Framework” dedicated to explaining how to integrate code highlighting in Flask. While there are free websites for converting code to HTML syntax highlighted versions4, they render the HTML a lot less human friendly to read, which makes it more difficult to look over the code you inserted into the post.
By default, Flask returns rendered files, which means that a specific HTML file is constructed based on a template each time a user requests a url. This is useful in cases that you want the user to see custom HTML files depending on the context, for instance, providing custom welcome messages to each user along with their last login date.
However, for a blog serving static content, the time to render to an HTML file simply adds unnecessary lag time. So one option is to put all your files in a special static folder in your project directory, and Flask will know to serve them statically5. However, that still means you need your backend to have Python, Flask, and a WGSI server.
Another option is to use Frozen-Flask, which will freeze all the pages in your Flask application and generate static HTML files that you can put directly on the server. However, as of this writing, the github repository hasn’t been updated in over 2 years, which increases the likelihood that it is no longer completely compatible with newer versions of Flask (although I haven’t tried it myself). The existence of this library also shows just how much overkill Flask is for a simple, static blog.
Good luck blogging!