It seems I've got into web development more and more. As I'm sticking to a language I know and love, I'm using Flask - a super awesome microframework based on the powerful Werkzeug and Jinja2 libraries. Why not Django? No particular reason, I've used it before and just prefer how easy it is to get up and running with Flask!
For those too lazy to follow the links (shame on you!) here's a basic Hello World in Flask to make you excited:
from flask import Flask
In this post I'll show you how you can apply blueprints to small projects, like the todo example you go through in the Flask tutorial. Blueprints allow for a more modular Flask app, they can encapsulate related tasks and be reused in an application by changing URL prefixes. The Flask docs do a great job of explaining it!
Instead of dealing with raw SQL, I prefer to use Flask-SQLAlchemy so I can utilise an ORM. The model for a todo is as simple as you expect it:
And the change from defining views for a Flask app to views for a blueprint isn't that alarming. Here's the initialisation and the 3 basic views for a todo:
todos = Blueprint('todos', __name__, template_folder='/../templates')
I also created a blueprint to handle static pages, like the home and about page. If you structure your Flask app like a package, then in your init.py of your views module you can define your 404 view function as follows:
All in all, you got a well organised flask app!
I'm no web designer, and that site is somehow visually tolerable. Checkout Bootswatch for some free themes that replaces Bootstrap's standard ones. Technically this was supposed to be a weekend hack... but a great El Clásico occurred and life drove me in other directions, until about Sunday evening when I finally started coding this up!
Lastly, you can get the complete source code right here: https://github.com/msanatan/organise