top of page
Search

Blogging With Python and Flask

One of my New Year's resolutions (yes, I still make them, but rarely stick to them) for 2017 was to start a blog. I've been thinking about it for a while, and I had an idea of what I wanted to focus on, at least initially - rants about tech stuff. I've even got a few posts floating around in Word files from when I was feeling more proactive about it. But every time I felt motivated enough to actually make it happen I came up against the same question: which platform should I use?

I know there's plenty of website platforms, some of which cater specifically to bloggers - Wordpress, Wix and Squarespace spring immediately to mind. I've used Wix and Squarespace before, in a limited way, but I felt none of these platforms really allowed me the flexibility I'd need if I was going to be making meaningful posts about anything tech-y. Hell, last time I checked the personal account features on Squarespace, it didn't even allow embedding of Javascript into your posts or pages. Lame. With that in mind, and given I was required to learn the basics of Flask for a couple of projects at work, I figured I could probably build my own site from the ground up, giving me full control over everything.

So here we are. I built the thing and figured what better topic for the first post than documenting the process? Start to finish it took me about 3 days to get everything up and running. I cheated a bit. I had some bootstrapped boilerplate code in place from my past projects which dealt with the mundane stuff - user authentication, password reset, database setup and initialization and so on. I downloaded a free html/Bootstrap template from startbootstrap.com. I also borrowed heavily from the Flask tutorial by Miguel Grinberg, found here. He walks through the creation of a microblog platform, so it was pretty easy to adapt most of the things I learned to this project. I'd thoroughly recommend it to anyone looking to learn the basics of Flask, though it's a bit outdated now. His book is also great.

The stack is Python and Flask on the backend, with SQLite driving the UI. There is literally a Python module for everything, so there were very few wheels that needed reinventing. The most difficult part about all of this was actually the CSS. I hate CSS. Mad props to all you front-end folks out there - CSS is just dark Voodoo in my eyes. Spent over an hour on New Years Eve trying to make a damn navbar dropdown render properly. I hadn't even been drinking...

There's still a couple of things I need to get done. You may notice that the sharing buttons at the bottom do diddly-squat right now (so no sharing this riveting article to Facebook just yet). Some of the CSS still needs some tweaking (which I look forward to like a kick in the nethers). Simple search functionality uses a plugin for Flask called Whoosh. Rolling my own seemed excessive, but I might do it anyway. I'd also like to add a comments section so I can feed the trolls, but that can wait. I'm sure there's more features I'd like to add which I'll uncover as I go. The beauty of not being tied to a platform means that pretty much anything I want to build I can, within reason. As of right now though, I'm pretty happy with how things have turned out.


11 views0 comments

Recent Posts

See All
bottom of page