8 ms·
Ask HN: Why should I use Django?
I want to build an app allowing users to search local car for rent availability.
- alexbecker 10y agoDjango 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
- cmdrfred 10y agoAre you proficient in Python?
- xcoding 10y agoNo, I am learning. It's my project.
- appleiigs 10y agoIf you are learning Django is best. First, it will show you the basic way of structuring your app. If you use something like Flask while learning, you'll just mash everything together in some disorganized fashion. Flask is great for the experienced folk who know what they want, and want nothing else. Second, Django is batteries included, meaning it does a lot for you, allowing you to progress fast. You won't get bogged down in the weeds. You can dig deeper on specific parts after you have more experience. Third, there is so much learning material with Django. "Tango with Django" is my favorite. If you are learning, you need learning material.
- cmdrfred 10y agoI'm not sure what you are asking. I feel your time will be better served learning as opposed to trying to optimize what framework you use.
- brianwawok 10y agoDJango or RoR seem like the two "best" frameworks to learn on though. Both are fairly opinionated, and both have tons of documentation online. I am biased towards DJango, but I could not fault someone use RoR.
- cmdrfred 10y agoI prefer Flask myself, but its all kind of silly if you aren't reasonably proficient in Python or Ruby to start with. You are going to end up throwing out the first few projects you make anyway. I'd begin with learn python the hard way.
- brianwawok 10y agoIsn't that the book that only teaches python2 and just wrote a blog post yesterday confused on what a turing complete language is? Or did I get my wires crossed? I would 100% start in Python3 and DJango personally, but YMMV.
- cmdrfred 10y agoDidn't hear about any of that. The Python 2 to 3 gap isn't wide in my opinion, I move from one to the other without issue. I guess it depends on what kind of programmer you want to be. I believe you will have a deeper understanding if you work from the standard library outward.
- hiphipjorge 10y agoIf 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 10y agoI 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.
- collyw 10y agoI learned Python and Django together. I had a Perl background,so it wasn't a great jump, mainly just googling "python equivalent of <perl code>"
- dehugger 10y agoIve been learning python using Flask, which is very similar to Django, and overall I think its been a pretty great tool and learning experience.
- al11588 10y agoAll you need to do is use Django as the backend create a rest API and then use react or Angular to retrieve the data.
- garymoon 10y agoI have experience with Flask, that's why I have the same question. Any answers?
- brianwawok 10y agoif 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.
- deleted 10y ago[deleted]
- zitterbewegung 10y agoDo you want to make a CRUD app and know python with good documentation and batteries included? Use django.
- megamark16 10y agoDjango 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.
- falcolas 10y agoIf 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 10y ago> 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?
- anp 10y agoAnything involving asynchronous operations has historically been painful with Django. I know that new versions are improving on this, but I think for now it's limited to web sockets.
- dom0 10y agoThat has little do with Django; you'll find it's the same with any WSGI based framework, because WSGI is fundamentally a synchronous interface.
- falcolas 10y agoTrue, but it's still worth calling out since Django is a WSGI-based framework.
- pmontra 10y agoHow about using Celery and sending tasks to it? A customer of mine has a Django application which is little more that a web interface over a bunch of long running Celery tasks and it works pretty well. No status updates over websockets, but it could be added pretty easily.
- symmitchry 10y agoNice documentation in one good reason. The official tutorial is great.
- wahnfrieden 10y agoDjango 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.
- doc_holliday 10y agoHaving been using the Django REST Framework for my latest project, I can too confirm that the REST Framework is Django's killer app. The level of productivity in writing API backend you can get off it is insane.
- dfsegoat 10y agoUsing DRF and company in production 24/7. There are some quirks that I find a bit annoying (nested serializer write behavior) - but other than that it is great.
- 0xCMP 10y agoYep that + all the migration tooling in Django makes getting the API side of a website going very easy.
- vittore 10y agoDid you try Eve(flask based) at all of API ?
- ropable 10y agoWhat, no love for the built-in database migrations? That feature has to be second, at the very least.
- danpalmer 10y agoCould 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.
- dexterbt1 10y agoI'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.
- superquest 10y agoBefore 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!
- jonasvp 10y agoWe'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.
- stefantalpalaru 10y ago> It scales beautifully It wastes resources, both CPU and RAM, so scaling is usually throwing more hardware at the problem instead of rewriting the whole thing in a more efficient language/framework. > has a great security track record Does it really? How many of us are stuck on old and vulnerable Django versions because our clients won't pay for the increasingly non-trivial job of upgrading to the latest backwards-incompatible version? > the core team keeps up with the times and new technologies but does so at a sane pace and without rushing things That's a nice way to spin it.
- tedmiston 10y agoI'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.
- olavgg 10y agoI 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 10y ago> 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.
- andr 10y agoAfter 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.
- jasonthevillain 10y agoThe 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.
- cyberpanther 10y agoIf 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.
- odonnellryan 10y agoMy test for using Django is similar to yours: If I think the project will best be represented with more than one "app" then I will use Django. If not, I'll use Flask. App can be an API + another part of the site, for example.
- NumberCruncher 10y ago>>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?
- kej 10y agoMore like, every framework will sometimes get in your way, but it's easier to work around Django when needed than some others.
- tedmiston 10y agoNo, 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-1-8 https://www.twoscoopspress.com/products/two-scoops-of-django...
- dom0 10y agoDjango 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).
- dopeboy 10y agoI 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 10y ago> 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 10y agoAgreed. 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.
- dopeboy 10y agoCouldn'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.
- econner 10y agoLots 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 10y agoI 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.
- welder 10y agoThis 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-django https://wakatime.com/blog/14-pirates-use-flask-the-navy-uses...
- koliber 10y agoFiguratively 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 10y agoDjango 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 10y agoFor me the problem was it is easy to go too far with the Admin and hack everything in there. Its not that limited.
- idm 10y agoDjango 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.
- jstimpfle 10y agoI 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.
- dschiptsov 10y agoIn 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).
- pmontra 10y agoI 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 10y agoThose 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.
- rubberstamp 10y agoConsider 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 10y agoSlight nitpick - web2py has a database abstraction layer (DAL) rather than an ORM. It's kind of like SQL except written in Python.
- rayalez 10y agoAs 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.
- sunstone 10y agoBecause 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 10y ago> 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. :) :/ ??
- dv35z 10y agoAny 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 10y agoI 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.
- hobarrera 10y agoThings 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.
- kayman 10y agoIf 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.
- mrwebmaster 10y agoWhat about web2py? Isn't it another good option?
- kayman 10y agoAs your project matures, you'll notice Django has more things out of the box to use than most other existing python frameworks.
- aftbit 10y agoI'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 10y agoDjango'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.
- wenbin 10y agoPopular websites / online services that use Django: - Instagram - Pinterest - Nextdoor - The Onion - Disqus - Washington Post - Bitbucket - Eventbrite
- ericfrederich 10y agohttps://youtu.be/Niq-HoraNPo https://youtu.be/Niq-HoraNPo
- morissette 10y agoAnd thoughts for microservice architectures? I run flask for our microservice backend and have a angular frontend decoupled from the backend
- collyw 10y agoNo need for them in the vast majority of apps. Well thats my thoughts anyway.
- NumberCruncher 10y agoIf 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.