Live data from Hacker News

Eighteen months of Django

dangoldin.com

11–20 of 85 posts

Re: Eighteen months of Django

#11
post #9

Earlier quoted context omitted.

I think it really depends on what the project is. If it's relatively simple and you don't really want to deal with user registration/databases I'd say definitely go with Flask. Django does a pretty good job of those two but until it "clicks" you end up being confused.

Funny that I wrote that Flask is for advanced usage and you wrote that Flask is for simple usage. If the project is really simple - no database, no declarative forms etc. - then Flask will be better. But if you go to "medium complexity" Django gives you ready components which you need to integrate in Flask (SQLAlchemy, WTForms etc.). You also need to invent your own project structure, and Django already has a hardcod…

I actually disagree. Flask does not necessarily shine with projects of high complexity. The framework designers themselves say as much:

"However Flask is just not designed for large applications or asynchronous servers. Flask wants to make it quick and easy to write a traditional web application."[1]

Flask is excellent when you just don't need a bunch of the stuff in Django, and don't need the batteries to be included. It's not so much that Flask is suitable to high-complexity apps, but more that it's suited to highly custom web apps. Building a music sharing app based on jQuery mobile and backed by Mongo? You're better off with Flask. But at scale you're going to end up doing something custom.

Django is highly suitable if you need to manage users, have a variety of entities that lend themselves to the admin dashboard (more broadly, that the admin/public app metaphor even makes sense in the first place), and find a plug-and-play package system compelling.

They are both great frameworks, but "complexity" (advanced/simple) is the wrong axis along which to evaluate them.

[1]http://flask.pocoo.org/docs/design/

Re: Eighteen months of Django

#12
Using S3 for static media makes perfect sense, but does anyone have information on S3 when your contributors (users in the admin) are uploading lots of images for via something like django-filebrowser or a simple zipfile upload (that extracts the images into a folder)? I haven't seen anything like this in any examples.

Re: Eighteen months of Django

#14
post #9

Earlier quoted context omitted.

Funny that I wrote that Flask is for advanced usage and you wrote that Flask is for simple usage. If the project is really simple - no database, no declarative forms etc. - then Flask will be better. But if you go to "medium complexity" Django gives you ready components which you need to integrate in Flask (SQLAlchemy, WTForms etc.). You also need to invent your own project structure, and Django already has a hardcod…

I actually disagree. Flask does not necessarily shine with projects of high complexity. The framework designers themselves say as much: "However Flask is just not designed for large applications or asynchronous servers. Flask wants to make it quick and easy to write a traditional web application."[1] Flask is excellent when you just don't need a bunch of the stuff in Django, and don't need the batteries to be include…

The "large applications or asynchronous servers" bit might be better understood in comparison to the monolithic versus micro kernel debate. Flask is well suited for building complex applications that can be decomposed into simple moving parts with a clear separation of concerns. (My personal bias is that all complex applications can and should be developed this way.)

The documented limitation you reference is based on the WSGI server being used. "If your server uses some kind of concurrency that is not based on threads or greenlets, Flask will no longer be able to support these global proxies."[0] As nginx+gunicorn is becoming more popular, this isn't really an issue at all.

[0]http://flask.pocoo.org/docs/becomingbig/#scale-like-a-pro

Re: Eighteen months of Django

#15
post #2

As someone who is thinking about doing a python project, should I learn Django or just go with Flask? Any thoughts on those two?

Neither! Actually, as the others have said it completely depends on what you're making.

Django is great if you're making a standard cms type website. News feed, blog, etc. There's a bit of a learning curve but it gives you a lot of the scaffolding out of the box (and there are loads of examples to learn from). It has the biggest community (I guess?) so you'll always be able to find answers / libraries / sample code.

Use Flask if you really want to get a website up and running with half a dozen lines of code. You'll have to build everything else yourself; admin, authentication, etc etc - though there are good extensions for a lot of things too.

Thinking about it - if you don't know either of them, spend a day with Flask, by the end of it you should have a fairly good idea of what you get with it. Then run through the Django tutorials. It'll take longer but you'll be impressed with how quickly you can get something fairly complete up and running.

For me, I lean towards Flask (heavily). When you think about what Django does - it's basically a web container with a db/model layer and sensible scaffolding for the views (front and admin). I prefer to use SQLAlchemy (if I'm working with a relational db). In terms of the admin I think that the days of writing admin grid and edit screens that post back and forth to the server are numbered (I use REST and Angular now) - so that's not a bit of Django I use either. By the time you've ripped all that out you may as well save yourself all the config and just use Flask. Having said that - LEARN THEM BOTH. At least just a little bit so you can see for yourself where each one shines.

These days I approach it completely differently. My last two projects have involved a fair amount of complex business logic (and processing work). I've written the libraries I needed first as standalone packages, only introducing Flask as a final step. The web wrapper is just there to provide a web interface (mostly an api) access the db layer and glue it all to my libraries. I'd recommend this approach as it stops you from thinking along the lines of "ok, I'll need to create 3 Django apps, here are my models for each, should I put this code in the models.py or the views.py?" Instead you concentrate on making the real python code to do the heavy lifting, and you architect that sensibly without having to worry about how the web framework would normally prescribe it to be done. You'll end up with far more portable code in the long run.

Re: Eighteen months of Django

#17
post #7
post #2

As someone who is thinking about doing a python project, should I learn Django or just go with Flask? Any thoughts on those two?

If you are new to Python and just want to have a working project instead of tinkering, then Django is better suited. Flask is for more advanced uses where you need to have more control or be able to integrate components you choose (like SQLAlchemy instead of Django ORM, or a NoSQL DB).

I disagree somewhat.. I'm a hobbyist at best when it comes to programming. Like I've never actually shipped anything in my life. I recently decided to put an end to that to solve a problem for a family member's business.

They just wanted a simple web form, where the sales people could add notes throughout the day and then automatically email those notes to the owner at the end of the day.

I first tried Django and was quickly overwhelmed.. I switched to Flask and with the help of flask-login, flask-wtforms, and flask-mail, it only took me a long weekend to get it up and running.

Just a personal anecdote, but Flask was much easier for me.

Re: Eighteen months of Django

#18
Great short and concise article.

I'm in the process of writing a pet project using Django and would really appreciate your insights on what packages you find useful (as mentioned at the bottom of your post).

Re: Eighteen months of Django

#19

Great short and concise article. I'm in the process of writing a pet project using Django and would really appreciate your insights on what packages you find useful (as mentioned at the bottom of your post).

[deleted]

Re: Eighteen months of Django

#20
I'll add that if you need to background anything, django-celery makes it easy.

celeryd is also good for scheduling tasks with either single or periodic execution.

http://docs.celeryproject.org/en/latest/getting-started/firs...

You can also use it in a typical task queue role. It will pickle or serialize the Python objects that accompany tasks for transmission over the wire.

Post reply on HN