News for hackers. Stuff that matters.
Re:Django 2.0 released by sgt on Saturday December 02, 2017 @11:06AM (#15832460)
This is probably your best bet if you're just going to build a nice CRUD frontend for a business app, possibly with an API (via DRF). I am doing this right now on a project as it's the shortest path to a win. The API however is written in Java 8 / vertx.
Re:Django 2.0 released by whalesalad on Saturday December 02, 2017 @11:08AM (#15832471)
I’d posit that a simple crud app would take an order of magnitude less time with Rails. I’ve been a Django developer since 0.96 and have built dozens of apps with it. After transitioning to Rails, it’s hard to justify the use unless you’re in an evironment that absolutely must use Python.
Re:Django 2.0 released by fulafel on Saturday December 02, 2017 @12:08PM (#15832804)
Interesting. What would you say is the biggest reason for this >10x development speed difference?
Re:Django 2.0 released by whalesalad on Saturday December 02, 2017 @12:31PM (#15832940)
Django forces you to declare everything. Lots of manual boilerplate. Example, you must define every bit of a model in order for it to work. Rails is the opposite. ActiveRecord will ‘just work’ with the database. You can run rails on an existing db for example if it follows what are widely used conventions such as lowercase model name is the table, foreign keys are foo_id, etc...

This is where people fear the “magic” of things like pluralization of models to table name and introspection... but it’s all just code! You can read it and look at it and understand it. No magic here. Just convenience and a smaller mental model as an end developer.

Also... resources as a first clsss citizen is the biggest reason and the reason it defeats Django for this use case. You define ‘resources’ in your routing layer instead of just routes that map to a function. This allows you represent multiple crud actions with a single controller and even nest them, all with a few lines of code. Then you get access control for free on your sub resource, knowing you’ve already passed the parent checks and have that context.

Example: /users/:id/photos/:id

In this case, my Photos controller will already know who the user is (and if they can view these photos) based on work that the parent did. It’s single responsibility principle. You can even have a top level photos resource devoid of the user context and support both cases with minimal effort.

Yes, you can do these things in Django. But it’s not designed to make these things composable and seamless. I’d argue it’s not REST-friendly. Don’t even get me started on Django Rest Framework which is a massive beast in and of itself.

You get all of that out if the box on Rails. You can stand up extremely robust and ergonomic API’s with so little code you’ll feel like your cheating.

I should probably write a blog post.

Re:Django 2.0 released by knivets on Saturday December 02, 2017 @01:00PM (#15833097)
Rails is definitely more convenient to prototype, but the magic issue is real. You never know where a variable or a function comes from by reading the source -- you'd need to run a debugger to do that (in Python you can just follow the import statements). The overall Rails architecture feels convoluted and unnecessary complicated (Railties, Engines etc). I also dislike the fact that there is no single source of truth for data in Rails. You have schema.rb, but you can't edit that directly, it is generated by running `rails db:migrate`, so one might say that migration files are a single source of truth, which is inconvenient: I need to generate a migration, then edit the migration file to add any modifications not supported by generator script and finally add accessor and validators in model file. In Django we have a model definition as a single source of truth (data model, validations). Also, once I've created (or updated) a model definition, I run `manage.py makemigrations` and all necessary migrations (which capture the current data model state + what's necessary to do to perform a database migration automatically) are created automatically. I also like the fact that in Django data integrity is enforced by default.

Though, when it comes to prototyping, I think Rails is a much more convenient option. In Rails I can launch a working CRUD app with authentication in 10 minutes, literally. In Django I have to manually create directory structure, manually specify each route mapping, create and program controllers (views), etc. Django doesn't even have a built-in authentication templates, only controllers (views), so I end up writing this boilerplate over and over again. The other thing is that the authentication requires a username and password, which feels kind of clumsy, when every other authentication relies on email and it is not very trivial to modify that (built-in admin dashboard relies on built-in authentication for example).

Re:Django 2.0 released by ubernostrum on Sunday December 03, 2017 @02:01AM (#15836390)
Example, you must define every bit of a model in order for it to work. Rails is the opposite. ActiveRecord will ‘just work’ with the database

Someone still had to create that database with those tables in it. It didn't magically pop out of the aether. Your complaint, then, is not "you must define every bit", but with where you do it, since you have to define things no matter what.

And if you have an existing database you'd like to use with Django, 'manage.py inspectdb' will reverse-engineer a set of model definitions from it.

Re:Django 2.0 released by bmelton on Saturday December 02, 2017 @04:42PM (#15834252)
> you must define every bit of a model in order for it to work. Rails is the opposite. ActiveRecord will ‘just work’ with the database.

If you have an existing database, sure, Rails is preferred. If you're starting from scratch, the Django definitions can create the tables for you. If you do have existing tables though, you can use inspectDB to have Django create the models for you.

Re:Django 2.0 released by ralmidani on Saturday December 02, 2017 @08:02PM (#15835364)
I enjoy having a well-structured framework that saves me time and does not need to be spoon-fed. But I have a theory that no programmer ever died from writing an import statement.
Re:Django 2.0 released by collinmanderson on Saturday December 02, 2017 @12:39PM (#15832978)
Have you tried Django’s inspectdb?
Re:Django 2.0 released by mjfisher on Saturday December 02, 2017 @06:39PM (#15834986)
Just wanted to anecdotally affirm whalesalad's experiences with my own. I desperately wanted to like Django more than Rails (I just really appreciate python as a language), but I find projects much quicker to build in Rails. It really is the convention-over-configuration magic that makes the difference. There's less to do in Rails to add commonly used web/crud functionality - but it's much less explicit and relies on you getting all the conventions correct. Rails is really the only framework that I've found fairly hard to learn, simply because you have to memorize the conventions to know e.g. where to pluralize and what magic helper methods will have been auto-generated. It should be noted I've never worked on a large Django project - I suspect once a site's data structure and main functionality has been nailed down and you get a larger team involved, Python and Django's 'explicit is better than implicit' design philosophy will start to provide increases in efficiency.
Re:Django 2.0 released by jrumbut on Saturday December 02, 2017 @10:01PM (#15835726)
I feel like you can tell a good rails developer by finding who thought it was hard to learn. There really is a lot you need to know under the magic, and if you can learn to create compatible magic in your own code the framework becomes incredibly extensible.

My Rails projects have always been the ones that felt the most done on their initial release. That extra time not typing and configuring goes into caching, validation, UX, and making nice solutions to project specific problems that fit nicely and don't become pain points as time goes on. All these things that can feel shortchanged in other projects get more of the polish they need sooner.

Re:Django 2.0 released by cschneid on Saturday December 02, 2017 @11:56PM (#15836031)
I've worked on a handful of large to very-large Rails apps, and I find that after a certain level of size, you're dealing with a Ruby code base that happens to have Rails as the way it is presented. Rails' implicit functions are either obvious because you use them often, or just not relevant, since you're deep in plain Ruby objects implementing your business logic.
Re:Django 2.0 released by _arvin on Saturday December 02, 2017 @11:10AM (#15832489)
Python - Django

Ruby - Rails

PHP - Laravel

all nice choices

Re:Django 2.0 released by blunte on Saturday December 02, 2017 @11:45AM (#15832689)
And if you don't mind the learning curve (which will make you a better thinker!), I would add

Elixir - Phoenix

I wish there was a complete Clojure - ???

Re:Django 2.0 released by enraged_camel on Saturday December 02, 2017 @06:03PM (#15834756)
Elixir with Phoenix is phenomenal. An absolute joy to use.

Elixir itself is an excellent language that leveraged the strengths of the Erlang VM, and Phoenix is like a massively improved, blazing fast and reliable version of Rails.

Re:Django 2.0 released by guftagu on Sunday December 03, 2017 @01:24AM (#15836275)
I'd wait for the ecosystem to mature before building a business app with Phoenix. You never know what taken for granted library is missing in Elixir, and it's going to be damn hard to hire a developer experienced with Phoenix. Everyone on your team will be slow and will be making a steady stream of mistakes as they learn the framework
Re:Django 2.0 released by blunte on Sunday December 03, 2017 @03:27PM (#15839387)
I think Phoenix (and Elixir) is mature enough already to use in production. I've made pretty good, bordering on oracle-like :) predictions about directions in technology over more years than I care to think about; so I'm confident that Phoenix is only going to grow in use and positive attention.

It will be the logical successor to Rails. It already is.

That said, I use a good mix of Elixir+Phoenix and old-school cron launched Python utility scripts, and that works nicely. Anything that's difficult (probably because I am still a newb) in Elixir I can easily do out of band with a Python script.

But your point about difficult to hire experienced people is the reason for my reply. This is the mentality that is ruining IT and development. Yes, having someone with hands on experience in all of your tools is nice - a rare luxury in fact. But it's really not necessary. I would be quite happy to have someone that has willingly built something in Rails, Django, and Nodejs with an "Oh I can learn that" attitude. Especially if you come from a modern MVC framework, Phoenix itself is easy. Elixir is the part that requires some real effort, imo.

Re:Django 2.0 released by KingMob on Saturday December 02, 2017 @07:35PM (#15835243)
Closest is probably Luminus, but it's really just a Leiningen build tool that can pull in your choice of libs to stitch together. It's good, and speeds up Clojure web dev, but is in no ways a framework by itself.
Re:Django 2.0 released by baby on Saturday December 02, 2017 @11:33AM (#15832616)
Agree, note that Laravel was heavily influenced by RoR.

I personally find that Laravel is less heavy than Django which is way less heavy than RoR. I would never use RoR for small projects.

Re:Django 2.0 released by CraneWorm on Saturday December 02, 2017 @01:41PM (#15833263)
Scala - Play
Re:Django 2.0 released by BlackMonday on Saturday December 02, 2017 @05:29PM (#15834547)
I'm not sure about that. Compared to Django, RoR and Laravel it's not opinionated enough. No resources like RoR and Laravel, no buil-in database mapping, no built-in authorization etc.

btw: what do you use for the database access? Slick, Quill, Doobie, ScalikeJDBC, Anorm, Squeryl, jOOQ, Relate, Activate or something else? There seem to be gazillions of sql libraries for scala (although the big three and most relevant are probably Slick, Quill and Doobie).

And what do you use for Authorization? Something custom build? If I look at Laravel there are quite a few maintained authorization libs with ~1000 stars on youtube (even more if we count unmaintained), for play there is not really much (deadbolt, play4j and t2v/play2-auth, I don't count Silhouette since the lib is mainly about authentication).

Re:Django 2.0 released by mundanevoice on Saturday December 02, 2017 @12:14PM (#15832837)
How about performance? Bugs that might come up due to the implicit nature of Rails? Just curious, since you have seen both sides.
Re:Django 2.0 released by whalesalad on Saturday December 02, 2017 @12:25PM (#15832905)
The implicit “magic” thing isn’t a real thing. It’s a fallacy. I have not come across real world problems like this.
Re:Django 2.0 released by mundanevoice on Saturday December 02, 2017 @12:32PM (#15832950)
Well. I disagree that it is not a real thing. For better debugging, you need to know more what's behind the scenes. Personally, I have seen some of my colleagues struggling to find the cause or better architect the thing because most of the decision has been hidden/taken by the framework. Not saying, it's true for all Rails dev but for some beginners, it really bites them.
Re:Django 2.0 released by whalesalad on Saturday December 02, 2017 @12:36PM (#15832964)
Sure but there is magic everywhere. You trade convenience for the risk of not knowing the underlying mechanism in action. The inverse is long boilerplate code, setting up multiple services and factories and fooWidget stuff just to do a simple thing. It’s more clear, yes, but is it always better?

Rhetorical question by the way... just food for thought. There is a balance. I happen to love the convention rails imposes and the “magic” it offers. That being said, there isn’t anything about it that I consider wizardry or don’t understand. It’s just ruby.

Re:Django 2.0 released by mundanevoice on Saturday December 02, 2017 @12:43PM (#15832999)
> The inverse is long boilerplate code, setting up multiple services and factories and fooWidget stuff just to do a simple thing

Are you not talking about Java here? ;)

Clearer code makes it easier to reason and hence easier debugging. Correct me if I am wrong.

Also, it really depends on person to person on how they write the code. Django does not mean big boilerplate nor does Rails.

My main question was on performance. How do they stack up next to each other? Python3 with Django is really working well these days. You can also check out the performance improvement on Instagram because of it. https://thenewstack.io/instagram-makes-smooth-move-python-3/

Re:Django 2.0 released by odonnellryan on Saturday December 02, 2017 @10:15PM (#15835764)
I can get a fairly feature-complete Python up with Flask + Flask Admin, within a few weeks. 1-4 weeks I'd say is a good timeframe. Have done this multiple times. How does Rails stack up there? Not trying to enter a pissing contest .... I agree that Django is not faster than Flask for simple business crud apps.
Re:Django 2.0 released by Kpourdeilami on Saturday December 02, 2017 @11:16AM (#15832524)
Just out of curiosity, if the API is already being built in Java, why not just build a single-page-app to utilize the API instead of Django? I'd assume the deployment and overhead of maintaining a single-page-app would be way lower than Django. (i.e. uploading to s3 and setting up CDN vs. setting up a VM for Django with nginx, uwsgi, etc.)
Re:Django 2.0 released by richardknop on Saturday December 02, 2017 @01:38PM (#15833252)
One reason would be because you don’t know react or angular or whatever the latest js framework is. You have known Django for a decade and it still works so why waste time learning some js framework which might be out of fashion in 2 years.

Generate dynamic HTML on the server, that still works just fine. And codebase will be way simpler as you just generate HTML on page refresh. No need to fiddle with event listeners and DOM and AJAX or whatever.

Single page web apps are often wrong choice if you just need some UI other than some fancy dashboard. Let’s say you need an admin panel where you can do CRUD operations, that’s perfect for Django/Rails and would be much much more work as SPA.

Re:Django 2.0 released by mythrwy on Saturday December 02, 2017 @01:56PM (#15833348)
Static pages and full refreshes really limit what a page can do though.

My personal preference (for most use cases) is a combination. Some things are easier done in static templates but JS is needed to really bring a page to life IMOP.

Lately there is too much SP-appage around where there are simpler alternatives though, with that I'll agree. I guess it keeps people employed screwing around with webpack so there's that.

Re:Django 2.0 released by richardknop on Sunday December 03, 2017 @05:38AM (#15836985)
> Static pages and full refreshes really limit what a page can do though.

Yes. But for 90% of business UI cases, you have some sort of collection of pages (i.e. website = collection of pages not a single page with everything crammed into it) with navigation menu. You use the menu to navigate to different pages with HTML forms that submit POST data and do GET redirects.

Trying to cram an entire business logic into a single page is often detrimental, split it into multiple pages. Highly interactive apps that fit into a single page model is maybe 10% of use cases or less I have seen in my career last few years.

This is all just my opinion obviously but I just think SPAs are a fad that will hopefully go away.

Re:Django 2.0 released by boundlessdreamz on Sunday December 03, 2017 @10:02AM (#15837824)
I have never written an SPA but after writing a fairly complex ecommerce admin backend (handling orders, shipping etc), I wish I had. There are a lot of complex UI state and some of it would have been easier in React/Vue
Re:Django 2.0 released by sgt on Sunday December 03, 2017 @06:16AM (#15837097)
As someone already suggested, writing an SPA comes with a lot of work to get going. This is a side project I need to write, and then hand off to an external development team at some point. Then it helps to simplify the equation as much as possible.
Re:Django 2.0 released by Scarbutt on Saturday December 02, 2017 @11:28AM (#15832592)
Depending on the app, writing a SPA could be a lot of work vs just writing your UI as a frontend server.

About NGINX, is still needed in both cases IMO, for the API or the frontend server.

Re:Django 2.0 released by paulie_a on Saturday December 02, 2017 @11:44AM (#15832684)
Also APIStar from the creator of DRF is something to keep an eye on. It has Django integrations and I believe is async.
Re:Django 2.0 released by jrs95 on Saturday December 02, 2017 @12:16PM (#15832855)
It's not inherently async, but it supports async. Although database support for that isnt great, so I'd recommend just sticking to synchronous stuff for now unless you don't mind using raw SQL.

If it were me, I'd probably use something else before I tried to squeeze that much performance out of Python at this point to though. I hope library support catches up and it becomes more convenient, but I don't think a predominantly synchronous ecosystem has really successfully transitioned to async before.

Re:Django 2.0 released by mattgreenrocks on Saturday December 02, 2017 @12:47PM (#15833020)
AFAIK, C# navigated the sync-async transition well. Admittedly, this is a function of time, as it has had async/await for quite awhile.
Re:Django 2.0 released by jrs95 on Saturday December 02, 2017 @01:50PM (#15833311)
Totally forgot about that one. Having nearly everyone on one the same framework probably helped a lot with that. I don't think anyone else really has that advantage. Except maybe Ruby and Rails... Perhaps some good concurrency stuff will come of Ruby 3.
Re:Django 2.0 released by goodoldboys on Saturday December 02, 2017 @12:37PM (#15832968)
+1 for APIStar. I love Django but if all you want to build is an API, it can be a bit much. APIStar has been great so far in the one production API I've helped build even if there are a few pain points that come with using such a new framework.
Re:Django 2.0 released by Scarblac on Saturday December 02, 2017 @02:36PM (#15833582)
We use Django for large single page GIS web apps that still always need some CRUD somewhere (e.g. configuration is done through the Django admin). Parts that Django doesn't do can still be done in Python.
Re:Django 2.0 released by methodover on Saturday December 02, 2017 @03:28PM (#15833872)
What does GIS mean?
Re:Django 2.0 released by collinmanderson on Saturday December 02, 2017 @03:34PM (#15833902)
Geographic information system. Dealing with maps, etc.

https://docs.djangoproject.com/en/2.0/ref/contrib/gis/tutori...

Re:Django 2.0 released by Rotareti on Saturday December 02, 2017 @11:30AM (#15832597)
> This is probably your best bet if you're just going to build a nice CRUD frontend for a business app, possibly with an API (via DRF).

If I had to choose a framework for a web API these days, I would go with something that is async from the ground up.

Re:Django 2.0 released by blowski on Saturday December 02, 2017 @11:59AM (#15832770)
Why? Async isn’t cost free - it’s more complicated and that complexity comes at a cost. If your company has only basic needs, you have to question whether you’re providing the best value for your company by doing anything more.
Re:Django 2.0 released by jrs95 on Saturday December 02, 2017 @12:26PM (#15832914)
Especially when a platform doesn't have libraries that support it fully. Node and ASP.NET are the only fully async platforms I'm really aware of where this isn't a huge problem. Of course there are others with great but not async concurrency models as well. Regardless, it's definitely a minority of use cases where the concurrency model should even be a priority.
Re:Django 2.0 released by Rotareti on Saturday December 02, 2017 @03:04PM (#15833754)
> Why?

Because we are getting more and more CPU cores to utilize. I don't think this trend will stop soon. The software stack will have to adjust to this and it already does. The next generation of mainstream (highlevel)languages/frameworks will be those that are designed to easily utilize CPU cores. It may be more expensive for now, but it might pay out later and I think it's much more exciting. ;)

Re:Django 2.0 released by konschubert on Saturday December 02, 2017 @08:09PM (#15835393)
I honestly don't understand this argument.

With 30 workers threads in Python Django, I should be able to make very good use of 6 CPUs even if the workers only run 20% of the time.

Re:Django 2.0 released by konschubert on Sunday December 03, 2017 @05:51PM (#15840126)
I mean, actually think that I don't understand and would like to be educated.
Re:Django 2.0 released by yedpodtrzitko on Saturday December 02, 2017 @11:36AM (#15832641)
Django Channels [1] + ASGI is exactly that. However making that the default would be a hit to the very good backward/forward compatibility Django keep having.

[1] https://channels.readthedocs.io/en/latest/

Re:Django 2.0 released by sebazzz on Saturday December 02, 2017 @11:50AM (#15832719)
One disadvantage of Django is that database providers need to know a lot about the internals of the framework. This shows once you rely on a 3rd party developed database provider, which can break even on minor upgrades.
Re:Django 2.0 released by konschubert on Saturday December 02, 2017 @08:09PM (#15835397)
What do you mean with a database provider?
Re:Django 2.0 released by drdaeman on Saturday December 02, 2017 @11:26PM (#15835960)
Possibly, database backends?

Like those: https://docs.djangoproject.com/en/2.0/ref/databases/#using-a...

They are, indeed, quite complex.

Re:Django 2.0 released by baby on Saturday December 02, 2017 @11:31AM (#15832603)
I would rather use Flask for that.
Re:Django 2.0 released by cdancette on Saturday December 02, 2017 @12:16PM (#15832856)
Flask for a CRUD ?

I'd agree with you for a very simple API (like a simple slack/irc bot), but for a CRUD, you'll need to write a LOT of boilerplate code with Flask

Re:Django 2.0 released by JelteF on Saturday December 02, 2017 @12:53PM (#15833054)
There's flask-restless, which removes most of the boilerplate. There's still good reasons to choose django over flask though, but easy rest apis can be achieved with both.
Re:Django 2.0 released by mcny on Saturday December 02, 2017 @11:44AM (#15832686)
To me the beauty of a restful API in flask is that you don't need to commit to anything. As far as the user is concerned, as long as /api/v1/user/15 gives back the user details for user number 15 (after checking authorization if necessary). The person who follows in my footsteps should be able to rewrite things one end-point at a time (as long as we clean things up after every transaction) in any other language (go lang or rust or swift seem like best bets). At least that is my hope, even if the person who follows in my footsteps is me!
Re:Django 2.0 released by asfdsfggtfd on Saturday December 02, 2017 @03:02PM (#15833733)
This can be achieved with any framework.

(1) Write your new endpoint. (2) Proxy to it via your old one.

Or for a full re-write you might want to do things the other way.

(1) Wrap the whole old app with a skeleton of the new one - just proxying the endpoints for now. (2) Start replacing the endpoints.

Re:Django 2.0 released by znpy on Sunday December 03, 2017 @12:53PM (#15838590)
> (1) Write your new endpoint. (2) Proxy to it via your old one.

OR: (1) write your endpoint. (2) use something like apache's mod_rewrite to adapt endpoints.

Re:Django 2.0 released by edshiro on Saturday December 02, 2017 @11:42AM (#15832675)
I am learning Python right now and want to build a website using this programming language. Django and Flask seem to be the best frameworks for this purpose. I understand that Django has steeper learning curve and comes with "everything", whereas Flask is more modular and compositional.

If I were to use Flask, is there anything that I could not do but that Django could?

Re:Django 2.0 released by orf on Saturday December 02, 2017 @11:50AM (#15832718)
The advantage of Django is it comes bundled with everything you could need. Flask is simple, but then you need user authentication. Which library do you use? Is it updated and maintained? What about an ORM, forms, templating, localzation. Do they all work together?

Suddenly it's not so simple.

That being said, if your app really is simple (single file, under 100 lines) flask is excellent.

Re:Django 2.0 released by dizzystar on Saturday December 02, 2017 @12:41PM (#15832987)
Oh, come on. There are plenty of large websites written in flask. It's not that hard to use at all, and all those things you list are definitely a part of it. Hell, I have a 20 KLOC website written in bottle, and no one ever said it was poorly done, insecure, and so on.

The problem is that a lot of people writing Python web stacks don't know how to write Python at all, and no framework will save that shortcoming.

Re:Django 2.0 released by orf on Saturday December 02, 2017 @01:30PM (#15833213)
Part of my point was that if your site is going to be 20 KLOC then why not use a framework that is aimed at building 20 KLOC large sites rather than one that is aimed at writing 200 line sites.

Flask is advertised as a micro framework. if you want to rebuild Django with it then sure you can, but I personally can't see why you'd want to.

Re:Django 2.0 released by dizzystar on Saturday December 02, 2017 @01:38PM (#15833253)
Flask is used by Pinterest and LinkedIn, which I'm guessing are a touch more than 100 lines of code.

Flask is, of course, more powerful than bottle, and has less batteries included than Django. Saying Flask is good for 100 LOC sites is terrible advice, no matter which way you try to slice it. It isn't. It's widely-used and well-maintained.

Don't get me wrong, I like Django as well.

Re:Django 2.0 released by orf on Saturday December 02, 2017 @01:41PM (#15833267)
I've used Flask for single file sites with 10-250 lines. It's great (ish). What's bad about it? Your saying it's only good for writing large applications? How so?
Re:Django 2.0 released by dizzystar on Saturday December 02, 2017 @03:42PM (#15833952)
Your contention is that it's only good for small sites. I'm saying it's good for any sized site as long as you actually know how to RTFD and program in Python.

Django is no different. Django falls apart spectacularly in the hands of people who can't program.

Re:Django 2.0 released by thijsvandien on Saturday December 02, 2017 @06:37PM (#15834972)
Does eventually needing a truck justify driving one when for now everything fits in a van? The structure Django imposes on you may get in the way while you're still experimenting.
Re:Django 2.0 released by hakanderyal on Saturday December 02, 2017 @02:42PM (#15833611)
What I like most about Flask is, it provides the barebones for request/response handling, and gets out of your way. Add SqlAlchemy to the mix, and python handles the rest.

I'm using Flask, but building my apps with Python.

This simple/complex equation should be reversed IMHO. Want to throw together something quick? Go with Django, where everything you need is built-in. Want to build a big app? Go with Flask, and build your stack specific to your needs.

As a bonus, once you have built a complex app with your own abstractions/magic succesfully, it becomes faster for you to build new projects with your own framework than any other alternative.

Re:Django 2.0 released by simonw on Saturday December 02, 2017 @03:11PM (#15833801)
I've ever understood this argument. Any library you can pick and mix into your Flask app you could just as easily pick and mix into your Django app. It's all just Python.
Re:Django 2.0 released by Walkman on Saturday December 02, 2017 @05:17PM (#15834491)
not really. Did you ever tried to use SQLAlchemy with Django? Good luck with that.
Re:Django 2.0 released by jefurii on Sunday December 03, 2017 @11:07AM (#15838125)
You most certainly can. I've built several Django apps with Elasticsearch-DSL as a backend and another app with a completely custom backend (you need a really good reason to do this).

There are tradeoffs of course: you give up the Django admin and a bunch of other things, at which point we might as well have used Flask. But our shop has a number of other "normal" pure-Django apps so it makes sense for us to use Django as a common base.

Awhile ago there was a book called "Lightweight Django" in which the authors showed how to use Django in a stripped-down Flask-like manner. Ultimately Django is just a big bag of parts that you can use or not use.

Re:Django 2.0 released by ubernostrum on Sunday December 03, 2017 @01:38AM (#15836321)
Ever tried using SQLAlchemy with Flask?

It's exactly the same situation: either you luck out, and someone already wrote all the conveniences and utilities and integrations with components for you exactly the way you want them with exactly the set of other components you wanted, or you do it yourself.

Also, you could make a similar argument about swapping major components into, say, Pyramid. Most of the alternatives people promote to Django are not really some paradise of trivially-swapped-but-tightly-integrated components. They just do exactly what Django does, with a different set of "use these or lose the integration" components chosen up-front for you.

Re:Django 2.0 released by hakanderyal on Sunday December 03, 2017 @04:37AM (#15836806)
I've used SqlAlchemy with Flask. You only need a few lines of code to integrate them.

But yes, with Flask (or similar frameworks/libraries), you need to do the integrations yourself with the components you want to use. Advantage of Flask in this regard is, you don't need to fight with Flask to make it happen. That's why I'm saying it's better suited for complex apps that you want to build with your own abstractions.

The real problem is the cargo cult thinking when it comes to frameworks, instead of doing a cost/benefit analysis and thinking about trade-offs.

Following statements like "Django for complex apps, Flask for 100 lines of apps" without researching the reasons behind probably will result in more problems in the future.

Re:Django 2.0 released by ubernostrum on Sunday December 03, 2017 @01:45PM (#15838829)
You only need a few lines of code to integrate them.

Really? So you got all the things you get in Django -- ORM, forms with validation, etc. etc. -- from "a few lines of code"?

Somehow I think that's not true.

Re:Django 2.0 released by simonw on Tuesday December 05, 2017 @06:47PM (#15857289)
I built a project on Django and SQLAlchemy back in 2008/2009.
Re:Django 2.0 released by int_19h on Saturday December 02, 2017 @12:09PM (#15832807)
If your app is that simple, Bottle is probably a better fit than Flask (even more minimalist and non-opinionated).
Re:Django 2.0 released by jrs95 on Saturday December 02, 2017 @12:30PM (#15832936)
Flask is a great fit with smaller APIs but not tiny like this in my experience. Great support for SQLAlchemy and database migrations. Better than Django ORM in my opinion.
Re:Django 2.0 released by feydaykyn on Saturday December 02, 2017 @02:31PM (#15833558)
If you have little experience with backend development, Django may help you by forcing you to code into a predictable and sensible structure; Flask won't limit you in any way, which is great but It's easier to shoot yourself in the foot and its harder to keep a consistent codebase.

If you're familiar with SQL, it may take some time to adapt to the Django ORM, which is really great but favors ease of use over power.

All in all, with Django you'll fight to override defaults and with Flask to enforce them. I loved both enemies

Re:Django 2.0 released by protomikron on Saturday December 02, 2017 @11:52AM (#15832729)
> If I were to use Flask, is there anything that I could not do but that Django could?

No, but it might be simpler.

When I started doing webdev in Python I used Flask (it's so slim, they said) and I still like it, but if you have some kind of DB in the back and care about user management, Flask won't help you.

Most people then use sqlalchemy and specific extensions for Flask to handle the user and security stuff. Although this works, I would advise you to start with Django.

Re:Django 2.0 released by robertfw on Saturday December 02, 2017 @03:09PM (#15833784)
If you are learning python, I would stick with Django. It'll get the basics up and running for you and you can focus on python specific code. If you go with flask you'll need to be piecing everything together on your own, and then you're not just learning python, you're learning web application components and flask as well.
Re:Django 2.0 released by GlennS on Sunday December 03, 2017 @12:42PM (#15838543)
With frameworks, the more they do for you, the more risk you will end up fighting against them if you need to do something they're not designed for.

Django isn't particular bad at this (it has some escape hatches to allow you to e.g. write custom SQL), but it is overal still quite a big framework and it's certainly harder to bend to your will than Flask.

So, you need to know the extra things it gives you and figure out if they will be helpful for your website.

Loosely, Django is: routing + HTML request parameter handling + HTML rendering + templating + user sessions + lots of database read/write help, assuming simple CRUD access patterns.

Flask is: routing + HTML request parameter handling + HTML rendering. Then, if you want any of the other things, you go and find a library for them.

Re:Django 2.0 released by paulie_a on Sunday December 03, 2017 @01:56PM (#15838879)
I do not have much experience with flask, but I recently told a coworker: if you are fighting the Django framework to do something, atleast question why you are doing that because there is a good chance you are going down the wrong path. The caveat is, yes there are some times when that is necessary, but it is also necessary to question what you are doing, and why it isn't possible.
Re:Django 2.0 released by brianwawok on Saturday December 02, 2017 @11:49AM (#15832711)
I would miss the django ORM. Depends if you like the ORM.
Re:Django 2.0 released by systems on Saturday December 02, 2017 @12:37PM (#15832969)
i vote turbogears for crud apps
[dead]
Re:Django 2.0 released by lima on Saturday December 02, 2017 @12:17PM (#15832860)
But the trade-off isn't usually worth it.

The time you save initially you'll later spend fighting the framework or debugging its internals.

Python's "explicit over implicit" scales a lot better, especially with large teams.

(personal opionion of someone maintaining production-critical Django and Rails applications)

Re:Django 2.0 released by whatyoucantsay on Saturday December 02, 2017 @12:52PM (#15833045)
It was worth it in the case of Airbnb, Twitter, Teespring, Coinbase and many, many others. Once you find product market fit, you can afford to rewrite your entire backend if needed. If you don't win round one, then it doesn't matter how well your stack could have scaled.
Re:Django 2.0 released by jrs95 on Saturday December 02, 2017 @12:28PM (#15832918)
FWIW I've never had these issues with Rails, though it does make sense that this would be more common with Rails than most things.
Re:Django 2.0 released by jlgaddis on Saturday December 02, 2017 @01:54PM (#15833335)
FYI, I just downvoted you but for your edit, not your original comment. Perfectly legit, valid comments get downvoted here for bullshit reasons sometimes, I just ignore it and move on. (FWIW, I've never used Django. I'm not a developer.)
Re:Django 2.0 released by whatyoucantsay on Friday December 08, 2017 @12:00PM (#15880084)
My only concern for karma is as a way to gain insight regarding the opinions of the community and how broken it is.

The parent comment being flagged to death is enlightening on both counts. I also appreciate your telling me you'd comment and vote on a thread about a Django release even though you've never used it and aren't a developer. That's simply fascinating!