After discovering the python programming language from the Raspberry Pi, it turns out it can be used for many different purposes, one of these being to create web based apps. A web app is a website that actually does something other than show text and images (static content). Flask is whats called a web micro framework for python, basically a module that helps you turn your python script or function into something that can be interacted with via a web browser. Jeff Knupp has a great article explaining from basics what a web framework is and what it does.
I’m currently developing a couple if web apps with flask. One is for a client which generates software licenses and emails them to a customer who requests it via a website. The other is my own project that automatically creates a blog when I put an article in markdown format in my dropbox account.
Although there is lots of help on the web, i find myself coming back to three main tutorials for flask, and all of them have line by line instructions for all the code and setup:
1. Matt Richardson (Product Evangelist at The Raspberry Pi Foundation) gives a basic tutorial of setting up a hello world app coded and served on a Raspberry Pi. This is great for beginners, it only requires a few steps to get it working on your pi, and you can have a web app up and running in minutes! On the same page is a little for detail on how to set up your Python-Flask Web app to interact with GPIOs – so for example turning a light on and off in your house via a web app!
2. Miguel Grinbergs Flask Mega tutorial. It really is mega! I used the first few steps to get my flask app setup, especially a couple of things almost every web app needs: working with online databases and user accounts. There is much more besides this, and at the end of the tutorial you’ll have made a fully functioning dynamic blog, a bit like a basic WordPress site, but coded by yourself. It should be noted that it is a little out of date, and I couldn’t get the database migrations to work (i. e. A helper program to update the database when you update the code, without losing data). So you may have to debug and search a bit if you get stuck.
3. Full Stack Python Guide to Deployments is a book by Matt Makai, but there is also a less detail more high level view on his website Full Stack Python. This is for advanced Python users looking to deploy their web app into production. You can certainly run a real live website from your Pi using Flask, but when you are deploying for high traffic or commercial use, you’ll need to set up a server and many additional parts of the ‘stack’, which are required for both security and performance reasons. The book is superbly detailed and dosn’t assume anything – right down to going through every command and configuration setting for deploying Flask web apps. I find it especially useful as my python skills are probably better than my linux sys-admin skills – it is well worth reading if you’re at the deployment stage.