Writing A Web App With Python

I have spent my spare time in the past two weeks writing a web app. I couldn’t find a good web site that offered an easy personal journal. I wanted something that was a bit like a blog but with less fuss and totally private.

So I decided to try writing one. The language choice was obvious, Python. The next question was which framework to use. I did a web search and discovered that the choice quickly came down to two.

Django is the older giant in the room compared to Flask. The two also have a different philosophies. Django has it all built-in while Flask seems to be a thin wrapper over Werkzeug and Jinja2 mostly providing request and session handling while leaving almost everything else to extensions.

I made my decision by doing the a tutorial in each. I started with Flask and quickly built a simple blog application. I was impressed. Django was a slower more complex time to do the same. My decision was made, Flask it would be.

Do not get me wrong, if I was building a major web app I might decide differently. I might also decide differently if my programming style and philosophy were different. In this case Flask matched my need and style.

I started out with some simple modifications to the tutorial app, Flaskr. This was adding the timestamp to both the database and the web page and adding Markdown processing to the entry form using Markdown2.

I started reading Flask Web Development: Developing Web Applications With Python and this was a huge help for the rest of the project. (Thanks to the local library and the interloan system for getting me the book.)

At this point I added flask-script for easier debugging.

This went well so I moved on to the next steps, I changed the database handling to use SQLAlchemy with Flask-SQLAlchemy and moved to bootstrap with Flask-bootstrap to make everything prettier. The final steps were to allow post editing and add pagination to the front page using SQLAlchemy’s pagination routines (Jinja2 looked after making the page backwards and forwards look good with a macro.)

You can see how Flask’s philosophy of using extensions rather than having it all in one big framework made things easier. I added stuff slowly when ready.

The whole thing was relatively painless, my biggest problems were with CSS, never my strong suit. I also improved my Python skills along the way.

You can see the result in the github repo. There are still a couple of changes I want to make, the next is improved security.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s