I have written flask recently,with a little project that I can study python.
I used to write Ruby on Rails, which is a very famous web framework and the most popular web framework all over the world.Rails is really really fast to develop most web products,MVC with RESTful design makes very thing easy. Based on meta-programming, the ActiveRecord makes data handles fly in the air.
But flask is also an awesome web framework after a few days since I write my project.It’s more like sinatra,which is a light ruby web framework.
With rails,you need to handle a request URL at
This code will handle
/blogs GET method to a controller named
app/controller/,and pass the params to function named
index. After process the request,rails will render a view named
With flask,you need to handle a request URL at
1 2 3
In my own words,ActiveRecord is much better than SQLAlchemy.
The Types of Associations in Rails:
- has_many :through
- has_one :through
Here are some data relationship implements of two ORM:
One to Many
1 2 3 4 5 6 7
Now you can get a customer’s orders by:
Get an order’s customer by:
1 2 3 4 5 6 7 8
Now you can get a user’s apps by:
Get an app’s owner by:
Many to Many
Although you need migration files in rails,since Flask and SQLAlchemy just configure data structure within model.The benefit of migration files comes out when you want to change your data structure of model.And now I finally known why my teacher ask me to design data structure at first,because other web framework have no ideas about what if our data structure changed.
With migration files in rails, you can change you data structure so easy that you can develop really really align.All details about the program becomes more and more clear after you start coding.