Hacker Newsnew | past | comments | ask | show | jobs | submitlogin
The Flask Mega-Tutorial (2012) (miguelgrinberg.com)
147 points by Tomte on Nov 18, 2018 | hide | past | favorite | 32 comments


Miguel's Mega-Tutorial was invaluable to me when I was learning Flask circa 2011-2012. It's a great resource.

That said, IMHO, if you're going to implement a simple CRUD app in Python, you may as well just use Django. Django includes all of the "batteries" for handling forms, authentication, databases (the ORM), etc. right out of the box. I think Flask has its place; but when it becomes a simple reimplementation of Django, I'm not sure I see the point.


Personally I much prefer the lack of magic in Flask and would far rather make a crud app in Flask than Django. Whenever I have to use Django I'm endlessly frustrated by the fact that everything is so abstracted and there's so much magic that most of my stack traces show only ~30 lines of Django internals and none of my own code.

Another (old but still excellent) resource for anyone learning Flask: http://mattupstate.com/blog/how-i-structure-my-flask-applica...


Totally agree, Django's ORM is fantastic, and everything else is fine. Combine Django with Django REST Framework and you've got a great way to build an API in no time flat.

For projects that don't require an ORM, or work with databases that Django doesn't support, I'm not as big a fan of Django, however.

There's an idea floating around on my team right now that literally all of our projects, even non-webapps, should be Django (I got questions about my use of -m recently, was told a "management command" would have been better), so I'm sensitive to this "just use Django" advice, maybe.


If people want "batteries included" solutions then nowadays they are better off going with spring or ASP.NET Core.


Why? I use Django and its pretty good.


I wish you had written a more detailed answer. I have to say I am really impressed by ASP.NET Core MVC on first look. I would love it if you had suggested something like the OP's Mega Tutorial for .net core. Then we could all have taken a look, rather than just taking your word for it.


This Github project "Flask-base" is great to start a flask project : https://github.com/hack4impact/flask-base Lots of things are included, user management/permissions / redis / SQLAlchemy ...


This is really good! I must have a play...


The link says it's from December 5th, 2017, so not 2012. Probably worth changing in the title here on HN.

https://www.kickstarter.com/projects/1124925856/the-new-and-...

Thanks 'windexh8er for mentioning something in the first place.


one thing i always see glossed over is using application factories [0]. they are a bit harder to grok initially, since you have to hook your dependencies up via the factory, but they really help with testing/deploryment and scaling up flask apps. it's so much easier to do it at the start than to try and retro-fit it. similarly, blueprints from day 1 also make sense.

[0] http://flask.pocoo.org/docs/1.0/patterns/appfactories/


> one thing i always see glossed over is using application factories [0]. they are a bit harder to grok initially,

IMHO what makes app factories hard to grok is the poor documentation and examples/tutorials on the topic. The official docs mention app factories are great but then don't include any clear example on how they could be used with routes. They do include examples that don't use app factories, thus that's what newbies use to get up and running, and afterwards keep on using because it works.


I've been using Flask for a few years now, and the other day had to whip up a small app for a task at work. This is the first app I've used Blueprints and Application Factories, so I'm looking forward to better understanding their payoff in the future.


Do you know of a good side-by-side comparison of a simple app built with blueprints versus one without? I am still trying to wrap my head around the problem that they solve.


thing is, a simple app won't show you the benefits. blueprints are basically modules, and allow you to compose a big flask app from multiple blueprints. so as your app grows, you can add new features sanely (especially routing). a nice side-effect is having to think as features being correctly separated.

initially, it's only a bit more effort, but as you scale it'll stop e.g. your views.py getting out of control, without resorting to hackery.

again, it can be hard to do retro-actively, and once you realize you need it, the codebase is usually pretty bad. so i just do it from the start, as the extra effort is small then.

(best practices prevent team members with less experience from committing attrocities and give them a good foundation to copy from)


Those interested in Flask may be interested in Quart (Flask compatible, but faster because of Asyncio)

https://pgjones.gitlab.io/quart/index.html


Asyncio does NOT make applications faster, especially if you are CPU bound.


But, most web applications are IO bound... dashboards, CRUD apps, simple wrapped up API calls etc.

For a truly CPU bound application, you ought to be looking at something other than Python IMHO.


I feel like I should mention Miguel's book.

It builds a similar kind of application. I would say it is complimentary. It is not as deep as, say, the Goat Book is on Django.

https://flaskbook.com/


I maintain a mid-sized (5000 LOC) Flask web app. Miguel’s mega-tutorial is required reading for new dev’s coming onboard the project.


This was such a life changer when learning flask! I wish all the techs had such a complete and well explained tutorial for beginners.


This is the tutorial that first taught me flask and the reason it’s my preferred backend framework today. Go Miguel!


I've been using this as a reference while building a webapp with flask. It's been treating me very well.


It's also not from 2012. Miguel did a major rewrite last year that was crowd funded. This is the updated guide.


Yes, this should have a (2017) tag, not (2012).


Interesting I forgot he did that.


Me too, it's great. Very well written and easy to follow.


Is this mega tutorial format better than the current trend of video courses? Do you guys have a preference?


I really dislike video courses. There is, usually, no good way to quickly scan for the important parts.

If there is stuff you already know, skipping forward minutes will keep you wondering whether you have missed something important. With text you can scan through unimportant parts relatively easy, while knowing you didn't miss something important.


Mega tutorials are a very poor format because they don't cover each topic in a self-contained manner, nor they provide a minimum working example to test.

However, they are way better than any video course.


I guess it depends on the type of person you are and how you learn best. In my case for example, I learn better by coding while following a video than when I have read through a massive blog post (Which involves a lot of copying and pasting). That said, text format is great in book form because you can easily reference a concept without having to scroll through an endless page. The only downside with books is you have to wait longer for the content to be updated. Just my 2 cents.


Anybody know something similar on Node.js, Express or MEAN?


https://devcenter.heroku.com/articles/mean-apps-restful-api

This tutorial helped me get started when I needed to build a MEAN webapp for a project




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: