
Ask HN: Why should I use Django? - xcoding
I want to build an app allowing users to search local car for rent availability.
======
cyberpanther
If you want to use Python then use Django. As with any framework, it can be
hard to work around but Django gives you the most options to work around the
framework than any other framework I've found.

Normally, if you are having a hard time with Django its because you're trying
to work around it the wrong way. This takes time to learn but Django can be
really elegant to work around and with.

The second option is Flask or Tornado which are pretty great too. Both would
give you more freedom but also less structure. I find it better to have the
structure because unless your an experienced engineer your Flask or Tornado
project will turn messy quick. Django projects can turn messy too, but at
least there is a more training and protocols for people to follow.

I use Flask/Tornado if I want to use Python and I know my project is a small
service and will probably not get big.

I use Django if I want to use Python and I know the project will grow over
time or I need features from the start like a database, migrations, cache,
etc.

~~~
NumberCruncher
>>Django gives you the most options to work around the framework

So Django stands in my way and its' advantage is that it is easy the work
around it?

~~~
tedmiston
No, I think you're misinterpreting the comment. Django guides you the right
way and how it guides you works most of the time. However, when you do hit the
edge, Django's very well written docs and thoughtfully designed architecture
guide you in building around its limitations. For example, if you want to swap
in Jinja over Django templates or SQLAlchemy over Django ORM. Really needing
to do so is still the exception to the norm, but just know that Django does
more here than most other frameworks.

If you are interested in understanding this a little deeper, I highly
recommend picking up the Two Scoops book [1].

[1]: [https://www.twoscoopspress.com/products/two-scoops-of-
django...](https://www.twoscoopspress.com/products/two-scoops-of-django-1-8)

~~~
idw
I second the Two Scoops book. Django documentation is excellent (try the
tutorial if you want a quick sense of django). Two Scoops help you understand
why to do things in particular ways and make good design choices within all
the things django can do.

------
jonasvp
We've built web applications based on Django for small CMS sites, large multi-
language CMS sites, up to large custom-built applications (mostly API-based)
for the likes of Mercedes-Benz and Deutsche Bahn. I can honestly say that I
never regretted the decision.

It scales beautifully (see the likes of Instagram, Disqus, Sentry, etc.), has
a great security track record, sane deprecation schedules, and the core team
keeps up with the times and new technologies but does so at a sane pace and
without rushing things.

Not to mention the documentation - ohmygod, the documentation!

In a nutshell: pick Django, keep learning Python, and try to build something
that your users love.

~~~
tedmiston
I've stopped citing Instagram as an example of Django scaling after learning
from one of their engineering managers at PyCon 2015 that they're running a
heavily modified internal fork of Django 1.5 or 1.6. It sounds like they
really have built their own framework (before today's Django + DRF existed).

Maybe this has changed post Facebook acquisition. I know Facebook is mostly on
Python 3 and modern stuff now.

------
hobarrera
Things I really like about django that are objectively good:

* A lot of _very common_ situations and patterns are already solved for you, and they're solved in the cleanest way possible.

* The documentation is excellent, both with "guides", examples, and API reference. Django (along with OpenBSD), has probably the best documentation I've seen around.

* Clean design (of django itself) means that you can extend it, or avoid using bits that for some reason don't suit you.

* Very transparent development, and the developers are really into open source - everything is done out in the open. This last point might not be really important as a user, but it helps if you ever want to contribute (or understand) anything to django itself.

\---

Even after years of django, I very occasionally still come across a
functionality in django that I'd overlooked and saves be a bunch of my own
code.

------
falcolas
If you have a usecase that matches Django's niche - i.e. a CMS style CRUD
application - you would have a hard time doing better than Django. If you're
not in that usecase, think long and hard about it. Django is fantastic to use
when writing with the framework, and a nightmare to work around when you need
to do something it doesn't easily support.

Your app does sound like it is in Django's wheelhouse (CRUD against a DB with
users), so it is probably a good fit.

~~~
avinassh
> and a nightmare to work around when you need to do something it doesn't
> easily support.

Can you elaborate more on this? And also for what kind of apps one should
avoid Django?

~~~
falcolas
Nightmarish (without building additional systems): Asynchronous operations
(i.e. any task that takes place _after_ you return a response), anything
involving websockets or long poll responses, anything involving cross-client
communication through the server (like chat). Intelligent master/slave DB
routing for read-only queries.

Hard: Using any DB but PostgreSQL. You can use other DBs, but Django silently
disables features. Doing anything with the DB that isn't directly managed by
Django itself. Doing anything but basic pre-defined URL routing as supported
by their routing system.

Use something else: Not using a relational DB as a backend. Not using their
user management and authentication system. If you want to use something other
than their built-in ORM, templating, and routing.

I personally recommend Flask in the cases where Django is not a good fit. A
threading/forking fastcgi model with basic nginx caching is incredibly
performant. That said, Flask is pretty terrible at most of the "nightmare"
level tasks as well.

~~~
rayalez
Are you familiar with django channels?

[https://blog.heroku.com/in_deep_with_django_channels_the_fut...](https://blog.heroku.com/in_deep_with_django_channels_the_future_of_real_time_apps_in_django)

They supposed to make this sort of thing easy and straightforward. I'm still
learning them, but this system seems to be well designed and makes a lot of
sense.

Django + Django REST Framework + React should give you pretty much everything
you need to build whatever you want, including single page apps. At least as
far as I understand it.

~~~
wahnfrieden
Channels don't guarantee at-least-once delivery, so you can only use them at
best as a refinement - you have to assume your clients will miss messages.
Which makes it unusable for many use cases (though I'm sure many negligently
ignore it too).

------
wahnfrieden
Django REST Framework is Django's killer app (as Django is Python's killer
app). If you need an API, it's a great batteries-included way to build one.

~~~
danpalmer
Could you elaborate a little about DRF? I spent a day or so evaluating it
among some other options for an API in a Django project, and it seemed to be a
relatively poor player in the Django ecosystem and be quite complex for the
same outcome compared to other libraries. It seemed like it would be ok for a
DRF specific project, but in as a single part of a larger project it didn't
seem to fit well. That said, I have very limited experience with it.

~~~
teilo
DRF is at its best when you develop an application from the ground up using
it. It also "does the right thing," and helps you stay RESTful. In particular,
if you use its HyperlinkModelSerializers and its baked ViewSets, it just plain
works, no fuss. But it's important to know what these shortcuts are doing so
that when you need to write custom APIs that go beyond CRUD, you know what to
do.

For very simple APIs, DRF is overkill, and if I only need a couple JSON
endpoints, I don't bother with it. But if I need full access to my models, you
just can't beat it.

~~~
danpalmer
Thanks! Much appreciated.

------
superquest
Before I was sophisticated enough to investigate such decisions on my own
(given the mass of discussion freely available on the internet), I really
don't think it mattered which framework I chose.

So I'd suggest you just some popular framework and don't worry whether it's
the right one. Pick one and run with it!

------
dopeboy
I picked up Django early 2015 and it has been my choice of backend ever since.
Though I haven't used Django to build a fullstack application, I have used
Django REST framework extensively for my backend. Impressions over 1.92 years:

1) Great documentation. Well organized, well written. Good balance between
theory and examples.

2) Superb ecosystem. Coming from PHP land, I got the sense of a "anything-
goes" mentality. On SO, people who help are very much interested in doing
things the idiomatic way.

3) You get to practice Python!

~~~
dozzie
> 3) You get to practice Python!

Not really. You mostly write Django and need to go really far before hitting
any non-superficial Python feature.

~~~
collyw
Agreed. I moved to Python form Perl 5 years ago because of Python. I feel I
never know Python as well as I knew Perl, but I do know Django really well.
But then the built in functionality means I rarely need to go too low level
with my code.

------
rubberstamp
Consider Pyramid web framework. Deploy it on gunicorn server with eventlet
workers. Use pushpin if you need realtime.

Its easy, it scales, use any DB and Pyramid framework has good documentation
too.

Or go with web2py if you need to start simple and easy and fast prototyping.
It has an ORM which supports many Relational DB and MongoDB too if you need
it. It has good documentation. Its authentication and authorization system is
too easy.

Stick to python3.

Really good python learning resources.

[http://www.diveintopython3.net/](http://www.diveintopython3.net/)

and

[http://greenteapress.com/wp/think-
python-2e/](http://greenteapress.com/wp/think-python-2e/)

~~~
tim333
Slight nitpick - web2py has a database abstraction layer (DAL) rather than an
ORM. It's kind of like SQL except written in Python.

------
dom0
Django is a good framework, because it's opinionated about _the right_ things
(ie those that fit most very well).

Also, "there's an app for that". The ecosystem is large and healthy.

If you don't want Django cause it's Django, then Flask and Pyramid are other
excellent alternatives. There is also a swath of more specialized frameworks
(eg. Tornado).

------
dexterbt1
I'm copying here what I wrote back in 2013 to some other forum, much of it is
still true...

Django is mature, full-stack, flexible, has sound architectural decisions
behind it, relatively good security track record. There is a built-in admin
and permission systems to help with what you require. Batteries included such
as an ORM, templating, routing, forms. The Django third-party apps/module
ecosystem is rather large and accessible: from authentication, social media
integration, payment gateway integrations, APIs, to whole apps like invoicing,
helpdesk, etc.

------
jstimpfle
I don't have experience with Django, but you could also just build everything
yourself on plain WSGI (the python version of (Fast)CGI).

Note I am not saying "build a new, generic framework because all other
frameworks stink". Building libraries with the goal to support other projects
is a neverending task.

But only building the support paste as you actually need it is not a lot of
work. WSGI is a quite simple interface. I'm doing this myself and the support
I currently need is only ~500 lines. The only external library I use is jinja2
templates. As database I use plain sqlite3 from the python standard lib and in
some places text files.

If you don't know and don't want to learn HTTP and Web application
architecture you will of course end up with a broken design. On the other hand
it's very rewarding to learn how to decompose an application into independent
components (templates, services, routing, database access, business logic,
authorization, session management, config parsing, project directory
structure, what have you).

The other big advantage is of course flexibility. If you do a good job the
decomposition is better than with a framework. This means flexibility. It's
easier to fix problems than with an opinionated framework.

------
olavgg
I think frameworks like Django, Rails or Grails are excellent tools for
building many business applications. Especially when there are plenty of CRUD
operations and complex workflows with different administrative roles. These
frameworks excels in developer productivity, stability and maintenance over
years.

I've been using Grails for over 10 years, my clients are super happy with what
I have delivered. I've built complex issue tracking systems, e-commerce web
sites, administration panels, data management tools and so on. Code I wrote 10
years ago is still working fine today! I highly recommend learning one of
these frameworks, you will make new friends and good money!

~~~
vorg
> Code I wrote 10 years ago is still working fine today

I'm wondering if any of it's been upgraded to Grails 3, or if they're still on
Grails 2, or even using a Groovy 1.x version of Grails.

------
kayman
If you're using Python and don't use Django (I've tried it as an exercise for
one of my pet projects), you have 2 options.

Create your own framework - writing http headers etc from scratch which will
take you forever or Use a lightweight framework like Flask or Web.py.

Either way, you'll end up creating your own ways to query the database and
creating patterns to communicate with frontend. As you write more code, you'll
abstract your code to reusable methods.

About a month into the project, you'll realize that you're slowly rolling out
your own framework which has grown organically.

Soon you'll realize you're better off using a polished framework like Django
which has abstracted many of the details so you can focus on delivering value
instead of clobbering together your own framework which will become a burden
to maintain alongside your app.

~~~
aftbit
I've always preferred microframeworks for exactly this reason. As you build,
you tailor things to what you actually need instead of building features that
match the framework. I've got one project that's built on flask + sqlalchemy,
but I've been slowly hacking sqlalchemy out of the fast paths because it is
just too slow and I'd rather improve my grasp of SQL than spend my time
learning SQLAlchemy.

~~~
crdoconnor
Django's opinionated nature means it fits together better. Random django
packages will do admin, ORM handling, etc. in a single consistent way whereas
flask packages typically don't.

E.g. what seems to be flask's most popular CMS uses mongo as a backend.

------
dv35z
Any Django developers who have made the switch to Play Franework (in Scala),
would you share your experience? About to go down that route, and would like
to know if it's as great as everyone says, challenges, etc. The usecase is
fairly mundane CRUD app, 10-15 interconnected tables.

~~~
paulddraper
I have.

Django does a lot automatically: authentication, schema creation, ORM, default
forms, admin interface. These are things useful to 95% of CRUD apps.

At a certain complexity, nearly every project would have to replace or mostly
replace all of those. A full table scan is prohibitive, you want to customize
indexes, you want to customize the design of everything, etc.

The Play Framework provides just that: an web MVC framework with basic
routing, templating, and HTTP utilities. It's more general and will scale
further in project complexity, but you should expect to spend more time
figuring stuff out initially.

\---

Other than that, there are the obvious differences between Python and Scala.
Personally, I love, love, love the confidence of static verification, but
there are good things about both sides.

------
alexbecker
Django is great for fast prototyping if you need very dynamic pages (because
views written in Python are so powerful), a complex site structure (because it
has excellent url routing), and lots of database interaction (because of the
ORM). If you only need the first two, I recommend Flask instead.

But be careful if you intend to create a stable, heavily-used site. I have so
many problems with Django in this use case that I've gotten tired of listing
them each time it comes up and collected them into a blogpost:
[https://alexcbecker.net/blog.html#django-is-
terrible](https://alexcbecker.net/blog.html#django-is-terrible)

------
megamark16
Django gives you a ton out of the box, with lots of sane defaults, but it
still allows you to override those defaults when you're ready for more
complicated functionality or business rules. I like the templating language,
it lets you drop a lot of dynamic functionality into existing html templates,
while staying out of the way for the most part.

------
econner
Lots of people will say not to use Django because ORMs don't scale. In my
experience, if you don't use an ORM you end up writing one (and doing a poor
job) in the early stages of a project. Usually this happens because you're
changing things quickly and favoring iteration time. You don't know what
you're building yet, so you can't choose the super optimized solution. Once
you need to scale things can become specialized and it's easier to go that
route because you have a better idea what you're building.

~~~
appleiigs
I like Django's ORM specifically because it automatically creates the database
migrations for you. Just change the model, then "makemigrations" and
"migrate", then you continue with the next task. Great for prototyping.

------
NumberCruncher
If you want to use python I would give web2py + intercooler.js a try. It is
"good enough" for most CRUD pet projects. Reading here the comments about
Django's advantages an inner voice always says "fine, web2py has it too"
except the excessive documentation and the weird non-pythonic syntax.

If you want to make something really professional just ignore the words of a
n00b.

------
koliber
Figuratively speaking, Django gets you from zero to 60mph in 2.4 seconds.
Getting from 60mph to 100mph takes 20 seconds. Going above that takes a lot
more time.

Lacking details, it seems like your app could be a good candidate for Django.

For me, the main appeal is the Django admin. It gives you a great way of
interacting with your data with minimal effort.

~~~
yen223
Django admin is great in the early stages of a project, when you just need to
quickly bring up a page to view your data.

I highly recommend ditching the admin page as soon as you can though - the
number of things you can do with it is extremely limited.

~~~
collyw
For me the problem was it is easy to go too far with the Admin and hack
everything in there. Its not that limited.

------
rayalez
As far as the backend frameworks go, you have the 3 most popular, very good
options:

\- Ruby on Rails

\- Node + Express

\- Django

The major reason I have picked Django is that it is written in Python, which
allows me to use an elegant and beautiful language that I can apply in any
field, and utilize a huge amount of python apps, scripts, and stackoverflow
examples.

Using Django has also enabled me to learn the solid foundations of web
development, which I can expand upon and apply anywhere.

For example now I am experimenting with React and Express, and knowing Django
helps me enormously, it makes understanding these things way easier.

I have built a bunch of projects with Django, and I am extremely happy about
my choice, so I highly recommend it to anyone who is beginning to learn web
development.

------
idm
Django has excellent documentation. Whether you're a beginner or an expert, it
is appropriate. That is to say: there are good tutorials for starting out and
there is good reference material for going deep.

As others have mentioned, Django is opinionated and I think they get it mostly
right.

I use Flask myself, in part because I wish for my data modelling language to
be a separate part of my stack, but my use of Flask is heavily influenced by
Django's philosophy.

I am the primary developer of Flask-Diamond, which attempts to adapt Django's
opinionated choices to Flask. However, I would still recommend that most
people start with Django.

------
welder
This post about Django vs Flask might help you decide to use Django or not:

[https://wakatime.com/blog/14-pirates-use-flask-the-navy-
uses...](https://wakatime.com/blog/14-pirates-use-flask-the-navy-uses-django)

------
jasonthevillain
The reason I keep sticking with it is the "optional batteries included"
approach. User auth, for example, is something that just works out of the box
with the admin/ORM, and has a lot of basic security necessities addressed.

In a more a la carte framework, such as Flask, there are packages to help with
user auth, but you have to do a lot more work to get them working with
whatever ORM you choose.

This means I can spend my time making products instead of wrangling packages
together.

------
andr
After spending several years developing in Django, I am currently building
something in a Scala web framework (not gonna name names) and the level to
which Django just works is utterly amazing.

If your application fits the use case - a mostly CRUD application based on
SQL, HTML-based or REST, no heavy real-time component - don't think twice
about it. Of course, none of those factors are a hard limitation, but if you
stick to them, Django fits like a glove.

------
al11588
All you need to do is use Django as the backend create a rest API and then use
react or Angular to retrieve the data.

------
zitterbewegung
Do you want to make a CRUD app and know python with good documentation and
batteries included? Use django.

------
dopeboy
Couldn't anyone comment on the pros/cons of using Flask? Currently I've been
using DRF and it's been serving my needs pretty well. I'm curious if there's
anything to be gained from Flask.

------
cmdrfred
Are you proficient in Python?

~~~
xcoding
No, I am learning. It's my project.

~~~
hiphipjorge
If you're just learning Python, I would not recommend to start with Django,
since Django does so much for you. It does sound like Django would be a great
choice for your side project.

It seems it's one of those things where you have to decide: Do I want to learn
or do I want to build something and optimize for that.

~~~
j_syk
I actually taught myself python through Django. Basically started the tutorial
without previous python experience. When you start with the ORM and models,
views, etc, there is enough Django-specific stuff you have to learn anyway.

Not that I'd recommend this way... but 6 years later it seemed to have worked.

------
sunstone
Because you're a gentleman of exceptional demeanor, character and surpassing
technical judgement, who unfailingly chooses the best tool for the job at hand
from the Maelstrom of pretenders.

~~~
Lordarminius
> Because you're a gentleman of exceptional demeanor, character and surpassing
> technical judgement, who unfailingly chooses the best tool for the job at
> hand from the Maelstrom of pretenders.
    
    
      :) :/ ??

------
wenbin
Popular websites / online services that use Django: \- Instagram \- Pinterest
\- Nextdoor \- The Onion \- Disqus \- Washington Post \- Bitbucket \-
Eventbrite

------
morissette
And thoughts for microservice architectures? I run flask for our microservice
backend and have a angular frontend decoupled from the backend

~~~
collyw
No need for them in the vast majority of apps. Well thats my thoughts anyway.

------
ericfrederich
[https://youtu.be/Niq-HoraNPo](https://youtu.be/Niq-HoraNPo)

------
symmitchry
Nice documentation in one good reason. The official tutorial is great.

------
garymoon
I have experience with Flask, that's why I have the same question.

Any answers?

~~~
brianwawok
if you want to use sqlalchemy use Flask. If you want to use DjangoORM, use
Django.

Pros and cons to both. I guess you can find weird solutions that look better
one way or the other except the ORM.. but I don't really see it.

I currently like DjangoORM like 10% better, so I would use Django. It is my
favorite ORM I have ever worked with. Right balance of saving you SQL writing
time, while still having a good SQL escape hatch when needed.

If you hate DjangoORM, seems silly to suffer through it though.. use Flask or
something else.

------
pmontra
I read in an answer of yours that you're learning Python. I learned Ruby
myself with Rails in 2005 because I had no other reason to use Ruby back then.
Rails was a much lighter framework than Django is now. I would recommend to
start with something very lightweight, get the gist of it and move on to
Web2py or Django.

What you're looking for could be Flask or even something simpler like

[https://docs.python.org/2/library/simplehttpserver.html](https://docs.python.org/2/library/simplehttpserver.html)

or its Python3 version

[https://docs.python.org/3/library/http.server.html](https://docs.python.org/3/library/http.server.html)

Now, about Django...

I inherited a Django project and after a few months working on it I wouldn't
start a project of mine with it. Obviously customers can ask me to do anything
:-)

Disclaimer: I might be biased against it because I don't like Python much (it
looks like a badly engineered Ruby, and probably the other way around if you
like Python, no bad feelings).

First problem: coming from 10 years of Rails, Django is very weakly
opinionated, so you can arrange the project as you want, name the db fields as
you want, etc. This is not as bad as having no framework or using Flask, but a
developer joining a project might have to spend time to get familiar with the
general structure of it (and the bill for the customer keeps growing, so the
chances he won't be happy).

Second problem: it doesn't import automatically every model and module. It
gets tiresome to do that in every file and in the shell (and the bill...) This
is not a language thing because Ruby has to import modules too but somewhat
Rails works around that. Surprisingly it raised problems for me only a couple
of times. The sum of the time lost with Python in the last few months is
greater than the one I lost in Rails because of that.

Third: the templating language is not Python but some crippled down language.
Somewhat people still manage to write nice code with Web2py which uses full
Python in the templates. Rails too. Why not Django? More time lost to learn
one more thing.

Web2py is an alternative but it has its share of problems: the first two of
Django plus a very risky approach at migrations which are automatically
enforced as soon as you run the code. If there is a way to turn that off and
you really like Python or have to work with it, look at Web2py.

About the nice points, it's got everything that it has to be taken for granted
in a past 2005 web framework: tests, migrations, ORM. It doesn't miss any
particular feature, it's got a big community so it's a safe choice and I won't
steer customers away from it.

~~~
pythonaut_16
Those are all intentional choices and benefits of Python

1\. This gives you flexibility to structure your app in a way that makes sense
for what you're doing. In addition, I've found Django's approach to modular
apps to be far more manageable and approachable than Ruby's "all the
controllers go in the controllers folder" approach.

2\. Explicit imports is a Python thing and a huge benefit. I've looked at
plenty of Rails code bases where I had no idea where different functions and
variables were coming from. In Python/Django, you can always see the explicit
definition at the top of the file.

3\. The "crippled down" templating language is very intentional as well.
Django is preventing you from writing your application in the templating logic
(something I've seen too much of in Rails) All your template should be doing
is specifying how the data is to be rendered in HTML/whatever.

Really Python/Django could be said to be Ruby/Rails flipped on it's head.

Ruby itself isn't very opinionated (there are usually several ways to do
something), while Rails is.

Python itself is pretty opinionated (there should be one right way to do
things), while Django isn't.

In general it's a matter of opinion and perspective but I personal find Python
and Django to be much easier to work with than Ruby and Rails.

------
dschiptsov
In theory, one should take a look at web.py and flask first.. It will teach
essentialism and minimalism (web.py) and doing the right thing in a right way
(all of them and Python in general).

