Showing posts with label flask vs sinatra. Show all posts
Showing posts with label flask vs sinatra. Show all posts

Sunday, August 25, 2013

Scratching the surface with flask

Python is a strange beast. These days, I am trying my hand at django and right now am trying to do a bit of development in flask. As I was doing web apps in java/ruby before this, it is quite natural for me to compare django with rails and flask with sinatra.
However, I find flask a little bit more verbose than sinatra as it has a little bit more verbose metadata. Check out the following yourself:
 
from flask import Flask              require 'sinatra'
app = Flask(__name__)

@app.route("/")                      get '/' do
def hello():
  return "Hello World!"                "Hello World!"
                                     end 
 if __name__ == "__main__":
 app.run(debug=True)


To start off with, one of the nice feature is the presence of reloader by default in flask. If I saved the python file with syntax errors, the program crashed in the terminal. This is different with sinatra as it needs to be restarted (sinatra-reloader is not present as a default). The template engine, jinja (rhymes with ninja) is reminiscent of mustache template to an extent. However, instead of yielding within a master template, all the child templates must extend the master template itself.
So far, I have created a simple application that was previously working in sinatra in little over an hour. My initial experience is a tad disappointing with nothing really worthy of a mention. However, it can be deployed to platforms like google app engine that support python or heroku which pretty much supports all open source platforms now.