News for hackers. Stuff that matters.
Re:Eighteen months of Django by tesmar2 on Tuesday May 07, 2013 @05:55PM (#5671091)
As someone who is thinking about doing a python project, should I learn Django or just go with Flask? Any thoughts on those two?
Re:Eighteen months of Django by aidos on Tuesday May 07, 2013 @07:33PM (#5671586)
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 by mailshanx on Tuesday May 07, 2013 @11:44PM (#5672362)
What is your opinion about web2py? I started exploring it a week back, and it seems to have a lot of built in functionality. I thought it would be the easiest web framework to get started with (since it was originally built to help teach students about web programming). However, it seems to have a vast number of components, and it looks like learning all of it would entail almost the same effort as learning Django...
Re:Eighteen months of Django by ceol on Wednesday May 08, 2013 @03:08AM (#5672939)
Not the person you replied to, but my two cents.

The creator and lead developer, Massimo Di Pierro, is incredibly active and always willing to lend a hand with whatever problem you have. I've seen him around reddit (not sure if he's on HN) and even when he's met with the inevitable haters, he's always been friendly and cordial.

Just like you've said, web2py was originally made to teach people how to build websites, which really shows in its architecture. It forgoes traditional Python conventions ("explicit is better than implicit" being a major one) in order to be more beginner-friendly. Some of the more experienced developers find this annoying, but if you're coming from PHP or a fresh background, it can be much easier to get started. Just take a look at the overview on Wikipedia[0]. It gives a good outline.

This is coming from someone who doesn't even use web2py. I prefer Flask for personal projects and Django for work/group things, but I would whole-heartedly recommend web2py. Run through the book[1] and, if you don't like it, give the Django tutorial[2] a shot. If that doesn't mesh with you, there's Flask[3], Pyramid[4], TurboGears[5], and CherryPy[6]. (The last two I would not recommend for beginners, but they're still good!)

[0]: http://en.wikipedia.org/wiki/Web2py#Overview

[1]: http://web2py.com/book

[2]: https://docs.djangoproject.com/en/1.5/intro/tutorial01/

[3]: http://flask.pocoo.org/docs/

[4]: http://docs.pylonsproject.org/projects/pyramid/en/1.4-branch...

[5]: http://turbogears.readthedocs.org/en/latest/

[6]: http://docs.cherrypy.org/stable/index.html

Re:Eighteen months of Django by aidos on Wednesday May 08, 2013 @04:42AM (#5673175)
I've never used it so I really can't comment, sorry. There are a few that I've only skimmed the documentation for to see how they compare to Django / Flask. Bottle for example - when I look through the examples it seems so close to Flask that I don't feel I need to look any closer at it (so I may be missing out on something there).
Re:Eighteen months of Django by boffo9 on Wednesday May 08, 2013 @02:20AM (#5672827)
Web2py does badly with pycharm. So I don't use it.
Re:Eighteen months of Django by porker on Wednesday May 08, 2013 @03:23AM (#5672967)
> 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.

My feeling too. Are there any projects which are starting to create the boilerplate for this? I'm new to Angular, so looking for where to get started...

Re:Eighteen months of Django by aidos on Wednesday May 08, 2013 @04:52AM (#5673199)
Not that I've seen - I'm building a specific admin interface for one of my projects at the moment using this style (but I'm not making it generic). Architecturally the REST api is on one domain, the admin system is static angular on another domain and the front of the site (/sites - 15,000 of them) is a thin layer that makes calls back to the api.

It should be possible to build a completely generic frontend that just has a grid view and an edit view that you could wire to any REST backend. Then you could use flask-restful or Django Rest Framework or whatever else you wanted.

If you were going to go that route there's an angular directive for doing grids that would get you half way there: http://angular-ui.github.io/ng-grid/#/examples

Were I still building CMSs that's the approach I would be looking into.

Re:Eighteen months of Django by lucian1900 on Wednesday May 08, 2013 @05:29AM (#5673289)
To be fair to Flask, there are lots of libraries you can add to it (Flask-Script, Flask-WTF, Flask-Auth, Flask-Admin) that replicate pretty much all of the functionality of Django, but in a more modular fashion. For example, I can use Flask-Auth regardless of if I've chosen Flask-SQLAlchemy.
Re:Eighteen months of Django by aidos on Wednesday May 08, 2013 @08:47AM (#5673809)
Indeed - I just didn't want to push Flask too much but that's what I use and I bring in the libraries you mention as and when they're required.
Re:Eighteen months of Django by obviouslygreen on Tuesday May 07, 2013 @08:48PM (#5671829)
Flask is so simple that it's definitely worth picking that up regardless (in any case, I think it's well done and worth having in your arsenal).

However, for large web projects, Django beats it hands down. Doing similar work with Flask would require so much wheel-reinvention that it'd be hard to justify your time or your client's money when it's all built quite well already.

Of course it's not perfect, and it's not for everything. But it's a great general-purpose, medium-performance web framework. It becomes a pain on very high-traffic sites (perhaps more so than JVM-based solutions and on par with scaling Ruby frameworks), but if you use it in the right place and/or team up with systems people that know their stuff, it's a powerful tool for quickly building complex websites in a maintainable and intuitive way.

Re:Eighteen months of Django by porker on Wednesday May 08, 2013 @03:16AM (#5672952)
Good point, I'd not thought about the JVM based Ruby solutions which can be used. If they'd give more Scala-like performance..

IronPython?

Re:Eighteen months of Django by greghinch on Tuesday May 07, 2013 @08:45PM (#5671819)
I've been building (more or less solo) a web app marketplace for our startup for about a year now. I love Python, and had dabbled in Django and Flask prior to this, but built nothing with either to any significant degree. I went with Django because I was able to get something up relatively quickly, and I feel like that was a solid decision. I also am relatively confident in my ability to move towards Flask in the longer term if the Django app becomes too much, but I haven't experienced that yet.

Also Heroku has been mostly a godsend, as I haven't had to spend nearly any time on sysadmin stuff. One thing that caught me early on, not sure if it's a bug or what, but in Heroku, if you use git URLs for some of your packages in pip requirements (which is useful if you need to customize a package or more frequently fix a bug and can't wait for it to be pushed to pypi), Heroku's package cache has trouble knowing when to update unless you a) change the package version in its setup.py (may or may not be a good idea) or b) change the Python version in runtime.txt (kind of a pain as generally that means two deploys for an update, bump down one minor, then back up).

Re:Eighteen months of Django by aartur on Tuesday May 07, 2013 @06:09PM (#5671156)
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).
Re:Eighteen months of Django by mikeyouse on Tuesday May 07, 2013 @08:11PM (#5671717)
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 by obviouslygreen on Tuesday May 07, 2013 @08:55PM (#5671851)
Flask is definitely easier... it also offers far less. Which is fine in some circumstances -- perhaps many -- but the fact that Django has a steeper learning curve is due to the fact that it covers a lot more ground in terms of things many if not most web applications need.

This doesn't make it better, but it also doesn't make it worse.

Re:Eighteen months of Django by ConceitedCode on Tuesday May 07, 2013 @08:00PM (#5671682)
You might also want to take a look at Pyramid. There's pros and cons for each.
Re:Eighteen months of Django by HarryRotha on Tuesday May 07, 2013 @09:16PM (#5671911)
I absolutely love pyramid, but I found the learning curve for it to be much higher than flask or django. If pyramid had a few more things working in a simple way out of the box I would go for it every time.
Re:Eighteen months of Django by ioddly on Tuesday May 07, 2013 @06:05PM (#5671138)
I suppose it depends on what your goals are. If your goal is just to crank out some Python, I'd go with Flask (or my personal favorite Bottle).
Re:Eighteen months of Django by dangoldin on Tuesday May 07, 2013 @06:02PM (#5671117)
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.

Re:Eighteen months of Django by aartur on Tuesday May 07, 2013 @06:21PM (#5671211)
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 hardcoded one. When the project complexity is "high" then Django starts to be too limited/"hardcoded" and flexibility/minimalism of Flask starts to shine.
Re:Eighteen months of Django by numlocked on Tuesday May 07, 2013 @06:52PM (#5671391)
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 by dvanduzer on Tuesday May 07, 2013 @07:32PM (#5671581)
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 by espeed on Wednesday May 08, 2013 @03:28AM (#5672983)
"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."

Armin has said before that he needs to update/clarify that statement -- as dvanduzer said, it's not really relevant anymore.

Re:Eighteen months of Django by dangoldin on Tuesday May 07, 2013 @06:26PM (#5671238)
Haha yea you're right! Funny how my bias trickled through. I haven't done too much Flask customization and only use it for the one off simple project that just need a web interface.

Django is definitely more in the range of "we want you to write" this way but I've found it to be at least a bit more customizable than RoR. Flask is on the other extreme which lets you do whatever you want.. but you're the one who has to do it.

Re:Eighteen months of Django by hamax on Tuesday May 07, 2013 @06:09PM (#5671159)
I really like Flask but I still go with Django when I need the admin.