Current Project: μblog

It's a pretty dumb name, but I like the double meaning.

Recently I've been working on my first ever web-app. It's not an area I ever thought I'd be interested in, but I wanted to give Flask a go in order to broaden my knowledge of widely-used Python frameworks.

I started off following this fantastic tutorial, and built the application as suggested. I learnt a lot about how Flask works, and pretty much completed the whole thing - I didn't bother with any of the internationalization/localization, and I deployed it on my own server with some significant differences (e.g. using an nginx proxy to allow me to use the subdomain u.bede.club).

Now that I want to extend the functionality a bit more, I can see that some of the solutions are pretty clumsy. I don't, for instance, want to have to go to another page just so the 'follow' button works; I'd much rather have it work in place and not reload anything.

For this reason (and because I want to learn a more modern style of web design), I've decided to use AngularJS in conjunction with Flask-Restless to expose and use a ReSTful API for the site.

One other advantage of using AngularJS is that it's widely considered to "play nicely" with JQuery (which I'm using for some minor functions on the site, like greying out the Post button when the textarea is empty).

A minor setback I encountered when installing and testing AngularJS was that it uses the same {{ and }} delimiters as the Jinja2 Templating Engine (used by flask to render HTML templates with content from the current user session). I got around this by following this StackOverflow answer, and changing the delimiters to the unused [[ and ]].

With some difficulty (I hate relational databases), I managed to convert the User.followed_posts function into a db.relationship attribute for the User model. It even orders the posts by default! I'm still not sure that there aren't any bugs, but once I've tested it more thoroughly, I'll be able to hit /api/user with a GET request and search for the followed_posts key. Or something like that - possibly I'll need to use the search functionality in order to paginate the results and avoid loading several million at a time.

I'll write back here when I've got things working as intended, and removed the last vestiges of the view-based pseudo-API.