Flask It Up

I initially built this site as my first attempt at writing a PHP site. In the last few weeks I've rebuilt it as my first attempt at building a Flask (Python) site. It turns out that I like Flask way more than PHP. Flask reminds me a lot of ASP.NET (in a good way), whereas PHP reminds me a lot of Perl (in a bad way).

Don't get me wrong, I love Perl. But I used Perl to build websites back in the mid-to-late 90s and PHP reminds me of those days. I'm glad web development has advanced a lot since then. There probably are layers on to of PHP that make it a more efficient development platform, but they weren't obvious to me a beginner. With Flask, doing things efficiently was pretty straightforward.

Based on my very limited experience, Flask compares to PHP favorably in many ways:

  • Routes in Flask directly support dynamic URLs; I used mod_rewrite to get nice URLs with PHP
  • Templates in Flask are great; My roll-your-own templates for PHP worked, but they were very awkward
  • CLI commands in Flask is simple and convenient; CLI commands for PHP were a bit hacky
  • The Flask version of my site is 1.5 to 2x faster
  • Python (Boto3) was a bit easier to use to access DynamoDb than the PHP AWS SDK

Porting my DynamoDb-based blog was pretty simple. My DynamoDb table is completely unchanged. Some of the porting was just changing PHP-style lists and dicts to Python-style. At some point I'll share that code.

I found deploying the Flask version of my site to be a bit tricky. I wasn't able to get it running under Apache on my EC2 instances running Amazon Linux 2-- I had to switch to Ubuntu. That effort prompted me to experiment with AWS CodeBuild, CodePipeline, and CodeDeploy. Now, any PR in my GitHub repo kicks off a deployment to my test site. Deploying to my production site is just one approval away.

Feb 28th, 2023