Close

April 17, 2018

Flask

I’ve been studying Phyton for almost a year, now, and I love everything about it: the readability, the flexibility, and the PEP8 guidelines—they’ll make me a better programmer.

I’m interested in Python mostly as a vehicle to program in ROS (the next thing I’ll be teaching myself). I’m also curious about computer vision.

My experience, though, is in web. One of my mentors recommended I look into web frameworks add a way to deploy some protects online.

Flask or Django

There are quite a few web frameworks for Python out there but I quickly narrowed down my choices to two: Flask and Django.

They are both well documented and adopted, but after a bit of reading I decided to give Flask a shot. Django is really solid but it’s also more opinionated and comes preloaded with too much stuff for what I need right now.

Flask on the other end is fairly light (calling itself a microframework) while offering a generous registry of extensions.

Learning Flask

Again: it is well documented and adopted. It’s fairly easy to find resources to learn how to use it.

I’ve loved taking Lalith Polepeddi‘s Lynda course titled: Learning Flask.

I’m also going through Miguel Grinberg’s Flask Mega-Tutorial and it’s really well done.

Bonus

The Lynda course covers deploying the app to Heroku, which is a great way to get started on the awesome Heroku CLI. Remember that Heroku offers a great free plan to experiment with dynos.

Flask relies on a Python template engine called Jinja2, and it’s really fun to use—template inheritance in particular. For example:

{% extends "base.html" %}
{% block title %}Index{% endblock %}
{% block head %}
    {{ super() }}
    <style type="text/css">
        .important { color: #336699; }
    </style>
{% endblock %}
{% block content %}
    <h1>Index</h1>
    <p class="important">
      Welcome to my awesome homepage.
    </p>
{% endblock %}

The {% extends "base.html" %} syntax takes a baseline template and inserts custom blocks inside of it. Jinja2 also supports control structures and one can loop inside a template, for example.

Always more to learn

The tutorials build apps relying on PostgresQL, open source object-relational database system. It’s a great opportunity for me to learn the SQL access methods and I’m looking forward to learning how to add a database to a dyno in Heroku. I’m excited to think of the possibilities…

Thomas Deneuville lives in Upstate NY with his wife and two sons, where he writes about creativity, draws, codes, and plays the bagpipe.