Live data from Hacker News

Ask HN: Django vs. Flask

news.ycombinator.com

11–20 of 22 posts

Re: Ask HN: Django vs. Flask

#11

Earlier quoted context omitted.

I think the first objection one would raise is that you don't need an ORM at all. It all depends on the application, of course, but ORM means giving up a lot of control (and transparency, and understanding) of your database in exchange for a few shortcuts regarding things like M:M links.

IMO, if you're using an ORM because you want many-to-many to work in a neat way, then you're using an ORM for the wrong reasons. Use an ORM because tools like this: https://marshmallow.readthedocs.io/en/latest/ work really well with it. And tools for migrations: https://sqlalchemy-migrate.readthedocs.io/en/latest/ start to make sense in your code. You don't need an ORM to do either of those things, but it makes thing…

I actually wrote a blog post about my experimentation with ORM (here: https://joeclark.svbtle.com/understanding-the-m-in-mvc). From the viewpoint of a database geek, somebody who cares about his database, those gadgets you linked are further reasons to dislike ORM, because they do more of what ORM does: take away transparency and control in exchange for "shortcuts". And what happens when those tools fail? ("migrate" is particularly screwy).

No, it's a matter of philosophy. The newbie who has learned to code without ever being taught SQL, and the employee of an "agile" app sweatshop who doesn't care about the quality of his code or data, may prefer ORM for its' quick-and-dirtiness, or may use it by default because he knows no better way. I'm not saying that's wrong, but, there are other philosophies. There is the whole "craftsmanship" idea out there, that we should actually care about making things well. Jobs and Wozniak for example supposedly were adamant that the insides of Apple computers were designed well. If you care about your database and want to use special features like triggers, procedures, recursive queries in Postgres, etc., then ORM is about as helpful as clamshell packaging.

Re: Ask HN: Django vs. Flask

#12

Earlier quoted context omitted.

IMO, if you're using an ORM because you want many-to-many to work in a neat way, then you're using an ORM for the wrong reasons. Use an ORM because tools like this: https://marshmallow.readthedocs.io/en/latest/ work really well with it. And tools for migrations: https://sqlalchemy-migrate.readthedocs.io/en/latest/ start to make sense in your code. You don't need an ORM to do either of those things, but it makes thing…

I actually wrote a blog post about my experimentation with ORM (here: https://joeclark.svbtle.com/understanding-the-m-in-mvc ). From the viewpoint of a database geek, somebody who cares about his database, those gadgets you linked are further reasons to dislike ORM, because they do more of what ORM does: take away transparency and control in exchange for "shortcuts". And what happens when those tools fail? ("migrate"…

This is a good point, but it can definitely be applied to any abstraction. I don't think ORMs are the best use of abstraction, but I think they're far from the worst use. For most applications they let you do a lot more a lot quicker without knowing a lot of SQL.

> And what happens when those tools fail?

I haven't used any of these tools that don't let me fall back on raw SQL or writing my own migration in SQL and including it in my code (outside of the DB). So, I haven't had this problem, honestly! Most DB problems I've had are related to _design_. There is an argument there to be had: "Do ORMs encourage bad database design?" but it's a different topic, in my opinion.

> There is the whole "craftsmanship" idea out there, that we should actually care about making things well.

Making a website is a completely different process than making a chair, or remodeling a kitchen, or designing hardware for a computer.

I absolutely make technology that is great, and I do take pride in my work, but if I didn't use an ORM it'd take me much longer to make: and the application would be much less maintainable.

> If you care about your database and want to use special features like triggers, procedures, recursive queries in Postgres, etc., then ORM is about as helpful as clamshell packaging.

I use all these things all the time. I've created migrations in Django to create my Postgres FTS trigger function. Now all these raw-SQL migrations are stored very nicely in their own space, and in version control. And it's just like I typed them into the SQL prompt: but I can just look in my codebase and see what I did :)

You can'd even do sub-selects nicely in Django ORM, forget recursive queries. But you can use raw SQL when you need it!

Re: Ask HN: Django vs. Flask

#13
My suggestion for beginners:

- If you want to do simple apps that do not touch the DB, or any kind of persistence, you can start with Flask. Much simpler to start.

- For a more integrated experience on web development, including DBs, use Django. Their tutorial is very very good: https://docs.djangoproject.com/en/1.10/intro/tutorial01/

I teach these subjects in a local university to BSc and MSc students, and since I want them to learn fast and lots of functionalities regarding web dev, I go directly to Django (after teaching them basic http with python and sockets - like this: http://joaoventura.net/blog/2017/python-webserver/).

Re: Ask HN: Django vs. Flask

#14
You should try both. Choose a project and implement it using the two.

Start with a basic todo list. Then add support for permissions. Then add support for versioned entries. Then add a REST layer on top.

Re: Ask HN: Django vs. Flask

#15
post #9

It depends on the application. Do you care about how things work inside your database? Do you want to understand how the subsystems of your app (like authentication, security, the API, etc) work? Flask allows you (and forces you) to make your choices explicit. Django makes the decisions for you and hides its workings under layers of abstraction. I can see using Django to rapidly prototype some kind of CRUD app, but o…

> I can see using Django to rapidly prototype some kind of CRUD app, but on the other hand, you could just use Wordpress for that. Flask seems like it would be a superior platform for engineering anything non-trivial, especially if you care about how it works. I feel like I'm replying a lot in this thread! I think it's the other way around. If you want to QUICKLY prototype something, use Flask: it's light weight, and…

Use cookie cutter Django and just prototype in Django. Maybe 50 more lines than flask but it was a got clone not code you wrote.

Re: Ask HN: Django vs. Flask

#16
post #2

Flask for learning from the ground up. Django after coming to the realization that large Flask projects end up cobbling together 80% of what Django offers, usually poorly.

I think you're generalizing a little too much here. For something like an e-commerce shop, I'd agree. But for something truly custom, I find myself overriding a lot of Django's built-in functionality.

Kenneth Reitz made a presentation about this: https://speakerdeck.com/kennethreitz/flasky-goodness

Re: Ask HN: Django vs. Flask

#17
Django - but my advice is not to start from two scoops - its a great book but your best bet is to work off the djangoproject, or djangogirls tutorials as thats the common project structure. once you have a handle on this start reading two scoops

Re: Ask HN: Django vs. Flask

#18
I'm also a noob. To hack together a quick app to hit a few of the instagram endpoints I went with flask. In my case, it was just a matter of writing a few annotated methods, and plugging in some template files and I was up and running in a few hours!

I'm now looking at SQL alchemy and thinking I might try to taking another look at Django...

Re: Ask HN: Django vs. Flask

#19
post #3

You can get pretty far with Flask. You'll need an ORM, so you'll likely chuck SQLAlchemy in. Then you'll want easier access to SQLAlchemy, sorta like, you know, django does it, so you pick up https://github.com/mitsuhiko/flask-sqlalchemy . But you can't use pure SQLAlchemy models (easily), since this otherwise great extension for flask doesn't support it ( https://github.com/mitsuhiko/flask-sqlalchemy/pull/250 , yes…

I'm starting a project which will have a React Native app part, and I don't know if I should go with Django, Laravel or DRF on the backend... It will also need a web part. The database will be Postgres.

My last project I did in Go and felt like too much "stupid" typing, even though I understand the reasons things are that way, and I love the tooling around it, it feels kinda verbose for websites..

-- edit --

One of my doubts with Django is that I'm not sure my SQL will translate well into a "model".

Suggestions?

Re: Ask HN: Django vs. Flask

#20
You'll learn more starting with Flask because it provides less layers and components (and a far smaller codebase). Eventually you'll build up several of the pieces yourself or combine various libraries and eventually realize it would be much simpler to rewrite in Django. At least that's how it's worked out over the past few years for me on anything over 100 lines or so.
Post reply on HN